服务端:192.168.109.133? ? ?客户端:192.168.109.132
[root@server ~]# vim /etc/ssh/sshd_config
关闭服务端的防火墙和getenforce
[root@server ~]# systemctl stop firewalld #关闭防火墙
[root@server ~]# setenforce 0 #关闭强制匹配 0关1开
[root@server ~]# getenforce #查看关闭状态
Permissive
[root@server ~]# systemctl restart sshd #修改配置文件需要重启该程序生效
[root@server ~]# vim /etc/ssh/sshd_config
[root@client ~]# ssh-keygen -t rsa #--生成非对称秘钥,-t指定算法,rsa一种非对称算法
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 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:
SHA256:PxURTLA772Rf9iskfzhSNIMn/n/EV9eBbPoWQkS/PBA root@client
The key's randomart image is:
+---[RSA 3072]----+
| +E=.. |
| o+= . |
| o.=. o|
| *oB. +|
| S + B++.o|
| . * =. +|
| o @ ..+|
| * B +o|
| o *o+|
+----[SHA256]-----+
[root@client ~]# ll .ssh/
total 8
-rw-------. 1 root root 2610 Jan 9 15:56 id_rsa#私钥
-rw-r--r--. 1 root root 576 Jan 9 15:56 id_rsa.pub #公钥
[root@client ~]# ssh-copy-id 192.168.109.133
#把当前主机.ssh/id_rsa.pub 文件发送到133主机的~/.ssh/authorized_keys
或#scp .ssh/id_rsa.pub 192.168.10.130:/root/.ssh/authorized_keys
[root@server ~]# ll .ssh/
总用量 4
-rw-------. 1 root root 565 1月 18 10:44 authorized_keys
[root@client ~]# ssh 192.168.109.133
[root@server ~]#