第九单元

1.openssh-server    功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

2.客户端连接主机

ssh   [email protected]     ##用ssh的方式,以超级用户的身份登陆172.25.254.106这台主机

[[email protected] ~]# ssh [email protected]
The authenticity of host '172.25.254.106 (172.25.254.106)' 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                         ##连接陌生主机时需要建立认证关系
Warning: Permanently added '172.25.254.106' (ECDSA) to the list of known hosts.
[email protected]'s password:                                                                     ##远程用户密码
[[email protected] ~]#                                                                                                    ##登陆成功

Unit9

3.sshkey加密

1.生成公钥私钥
[[email protected] ~]# ssh-******         ##生成公钥私钥工具
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):[enter]     ##加密字符保存文件(建议用默认)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):         [enter]        ##**密码,必须>4个字符
Enter same passphrase again:                 [enter]        ##确认密码
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:                        
ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|o                |
|E.               |
|..               |
|.  . o           |
|.o. * . S        |
|oo.o o   .       |
|+ =. .  .        |
|o. oo.+..        |
|    ..o*.        |
+-----------------+

Unit9

[[email protected] ~]# ls /root/.ssh/      ##当执行完过程之后,会在/root/.ssh目录下,生成两个文件,有id_rsa ,id_rsa.pub
id_rsa         id_rsa.pub
id_rsa        ##私钥,就是钥匙
id_rsa.pub    ##公钥,就是锁

Unit9

2.添加key认证方式
[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub  [email protected]
ssh-copy-id                            ##添加key认证方式的工具
-i                                               ##指定加密key文件
/root/.ssh/id_rsa.pub            ##加密key
root                                          ##加密用户为root
172.25.254.206                    ##被加密主机ip

Unit9

3.分发钥匙给client主机
[[email protected] ~]# scp /root/.ssh/id_rsa [email protected]:/root/.ssh/

将服务端的/root/.ssh/目录下的id_rsa 文件用scp的方式发送给客户端,然后在客户端/root/.ssh/目录下可以找到这个文件

这个文件的作用就是下次再登陆服务端的时候不用输入密码,因为本地已经有私钥文件

Unit9

Unit9

4.测试
[[email protected] ~]# ssh [email protected]        ##通过id_rsa直接连接不需要输入用户密码
Last login: Mon Oct  3 03:58:10 2016 from 172.25.254.206
[[email protected] ~]# 

Unit9

4.提升openssh的安全级别

1.openssh-server配置文件
/etc/ssh/sshd_config
78 PasswordAuthentication yes|no        ##是否开启用户密码认证,yes为支持no为关闭

Unit9
48 PermitRootLogin yes|no            ##是否允许超级用户登陆
49 AllowUsers student westos            ##用户白名单,只有在名单中出现的用户可以使用sshd建立shell
50 DenyUsers westos                ##用户黑名单

Unit9

2.控制ssh客户端访问
vim /etc/hosts.deny
sshd:ALL        ##拒绝所有人链接sshd服务
Unit9
vim /etc/hosts.allow
sshd:172.25.254.206    ##允许250主机链接sshdUnit9

sshd:172.25.254.206, 172.25.254.180    ##允许250和180链接
Unit9
sshd:ALL EXCEPT 172.25.254.200       ##只不允许200链接sshd

Unit9

3.ssh登陆提示修改该
vim /etc/motd        ##显示登陆后字符
hello world        ##在登陆后就会显示这个字符

Unit9




相关文章:

  • 2021-04-10
  • 2021-12-24
  • 2021-08-16
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2022-01-23
  • 2021-09-13
  • 2021-04-28
  • 2021-04-09
  • 2021-10-05
  • 2021-11-03
相关资源
相似解决方案