天天看点

linux学习 lesson7 sshd服务

1.sshd简介

sshd= secure shell

可以通过网络在主机中开机shell的服务

连接方式:

首先设定虚拟机的ip:

1)在虚拟机desktop中

nm-connection-editor ## 打开ip设置

2)设置虚拟机ip

3)在主机上ping虚拟机地址察看是否完成。

linux学习 lesson7 sshd服务

##显示ping通,表示连接成功

配置好之后

ssh    [email protected]	##文本模式的链接

ssh -X [email protected]	##可以在链接成功后开机图形
           
linux学习 lesson7 sshd服务

注意:

第一次链接陌生主机是要建立认证文件

所以会询问是否建立,需要输入yes

在次链接此台主机时,因为已经生成~/.ssh/know_hosts文件所以不需要再次输入yes

2.sshd 的key认证

在实验之前打开虚拟机desktop和server 用两个虚拟机来实现操作,以免对真机系统造成影响。

(1).生成认证KEY

为了主机的安全也为了特定主机连接的方便,通常使用sshkey加密方式,如下图,输入命令"ssh-keygen",按三下回车后即可生成一对公钥和私钥。新出现的文件"/root/.ssh/id_rsa"称作私钥,"/root/.ssh/id_rsa.pub"称作公钥。公钥相当于是锁,私钥相当于是钥匙。

linux学习 lesson7 sshd服务

(2).加密服务

[[email protected] .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]   ##加密sshd服务
The authenticity of host '172.25.254.200 (172.25.254.264)' can't be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

[[email protected] .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
    ^
 此文件出现表示加密完成
           

(3).分发钥匙

scp /root/.ssh/id_rsa [email protected]:/root/.ssh/
           

(4).测试

在客户主机中(172.25.254.164)

ssh [email protected] ##连接时发现直接登陆不需要root登陆系统的密码认证

3.sshd的安全设定

78 PasswordAuthentication yes|no ##是否允许用户通过登陆系统的密码做sshd的认证
48 PermitRootLogin yes|no	 ##是否允许root用户通过sshd服务的认证
52 Allowusers student westos	 ##设定用户白名单,白名单出现默认不再名单中的用户不能使用sshd
53 Denyusers	westos		 ##设定用户黑名单,黑名单出现默认不再名单中的用户可以使用sshd
           

4.添加sshd登陆登陆信息

vim /etc/motd ##文件内容就是登陆后显示的信息

5.用户的登陆审计

1.w ##查看正在使用当前系统的用户

-f ##查看使用来源

-i ##显示IP

路径:/var/run/utmp

2.last ##查看使用过并退出的用户信息

路径:/var/log/wtmp

3.lastb ##试图登陆但没成功的用户

路径:/var/log/btmp