linux 的sshd服务

#####sshd服务#####

实验环境:

nm-connection-editor

ifconfig

##1.sshd简介###
sshd= secure shell
可以通过网络在主机中开机shell的服务

客户端软件
      sshd

连接方式:
      ssh       username@ip   ##文本模式的连接
      ssh   -X  username@ip   ##可以在连接成功后开机图形


 
      注意:
            第一次连接陌生主机是要建立认证文件
            所以会询问是否建立,需要输入yes
            在次连接此台主机时,因为已经生成~/.ssh/know_hosts文件所以不需要再次yes

远程复制:
        scp file  root@ip:dir         ##上传


        scp  -r   root@ip:file  dir   ##下载


###2.sshd的key认证####

1.生成认证KEY
[root@server ~]# ssh-keygen          ##生成密钥的命令
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):     ##指定保存加密字符的文件(使用默认)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):                  ##设定密码(使用空密码)
Enter same passphrase again:                                 ##确认密码
Your identification has been saved in "/root/.ssh/id_rsa."   ##密钥(钥匙)    
Your public key has been saved in "/root/.ssh/id_rsa.pub."   ##公钥(锁)
The key fingerprint is:
30:42:a5:0e:ae:8c:bf:ed:99:4d:7b:8c:93:a3:46:1e [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|    ...          |
|   . .           |
|  . o o          |
| . o . o         |
|  . .   S        |
|o.  E            |
|o. o ..+         |
| . .o==.o        |
|  o+*.o+         |
+-----------------+


2.加密服务
[root@server ~]# ssh-copy-id -i  /root/.ssh/id_rsa.pub [email protected]    ##加密sshd服务
The authenticity of host '172.25.254.111 (172.25.254.111)' can't be established.
ECDSA key fingerprint is 7d:cf:00:59:99:b9:b3:4e:40:33:f1:4f:9f:54:b6:58.
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/roo

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

[root@server ~]# ls /root/.ssh/
authorized_keys  id_rsa  id_rsa.pub  known_host
      ^


此文件出现表示加密完成

3.分发钥匙
[root@server ~]# scp /root/.ssh/id_rsa [email protected]:/root/.ssh/

4.测试
在客户机中(172.25.254.100)
ssh [email protected]   ##连接时发现直接登陆不需要root登陆系统的密码认证


#####3.sshd的安全设定#####
   vim /etc/ssh/sshd_config
78 PasswordAuthentication yes  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

猜你喜欢

转载自blog.csdn.net/weixin_42635252/article/details/81200927