ssh服务安装包openssh-server
主要的配置文件:
- /etc/ssh/sshd_config 修改端口号或允许登录用户名单
- /etc/ssh/sshd_config.d/01-permitrootlogin.conf 允许root用户是否登录
- /etc/selinux/config 修改selinux的工作模式
连接加密技术“非对称秘钥”:
- 公钥:提供给远程主机的,用来给数据加密
- 秘钥:自己产生秘钥,来解密被公钥加密的数据
实验1:修改ssh服务的端口号
修改配置文件
[root@server ~]# vim /etc/ssh/sshd_config
调整selinux
[root@server ~]# vim /etc/selinux/config
关闭防火墙,重启服务
[root@server1 ~]# systemctl disable --now firewalld
[root@server1 ~]# systemctl restart sshd
实验2:拒绝root用户远程登陆
请保持服务器上至少有一个可以远程登陆的普通远程账号
[root@server ~]# vim /etc/ssh/sshd_config.d/01-permitrootlogin.conf
[root@server1 ~]# systemctl disable --now firewalld
[root@server1 ~]# systemctl restart sshd
实验3:允许特定用户ssh登陆,其他用户都无法登陆
[root@server ~]# vim /etc/ssh/sshd_config
[root@server1 ~]# systemctl disable --now firewalld
[root@server1 ~]# systemctl restart sshd
实验4:linux客户端通过秘钥登录linux服务端root用户
[root@client ~]# ssh-keygen -t rsa 创建秘钥对
[root@client ~]# ll /root/.ssh/ 查看秘钥文件
总用量 16
-rw-------. 1 root root 2590 10月 3 16:51 id_rsa
-rw-r--r--. 1 root root 565 10月 3 16:51 id_rsa.pub
-rw-------. 1 root root 936 10月 3 16:52 known_hosts
-rw-r--r--. 1 root root 96 9月 23 10:58 known_hosts.old
[root@client ~]# ssh-copy-id root@192.168.37.100 复制公钥文件到服务器到该目录下
[root@client ~]# ssh root@192.168.37.100 测试连接是否要密码