作业:配置ssh免密登陆:客户端主机通过redhat用户基于秘钥验证方式进行远程连接服务器的root用户
1.实现免密登录
(1)使客户端产生公钥和私钥
产生的公钥和私钥都在用户家目录下的 .ssh/
[root@localhost ~]# useradd redhat -p redhat [root@localhost ~]# yum install openssh
(2)将客户端的公钥id_rsa.pub放到服务端的 authorized_keys这个文件中
[root@localhost ~]# ssh-keygen -t rsa [root@localhost ~]# ls -a . .bash_history .bashrc .cshrc Downloads Pictures .tcshrc .viminfo .. .bash_logout .cache Desktop .local Public Templates .Xauthority anaconda-ks.cfg .bash_profile .config Documents Music .ssh Videos [root@localhost ~]# cd .ssh/ [root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.226.128
(3)免密登录成功
[root@localhost .ssh]# ssh root@192.168.226.128
2.设置允许redhat用户登录
1. (1)创建用户并为其设置密码 2. [root@localhost ~]# vim /etc/ssh/sshd_config 3. (2)修改sshd的配置文件 4. ------在AllowUsers后面添加需登录的用户 5. AllowUsers redhat
- 重启服务
[root@localhost ~]# systemctl restart sshd [root@localhost ~]# ssh root@192.168.226.128