CentOS8 设置无密码SSH,SSH免密,SSH可信访问

一、SSH免密到本机

设置无密码SSH(是服务器间的无密码ssh,与用户相关)
现在检查您是否可以在没有密码的情况下SSH到本地主机:
[root@dev10 ~] ssh dev10 (机器名)
如果需要密码,请执行以下命令:
[root@dev10 ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
[root@dev10 ~]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[root@dev10 ~]# chmod 600 ~/.ssh/authorized_keys

[root@dev10 ~]# ssh dev10
[root@dev10 ~]# exit

二、设置SSH免密到其他服务器

1.其他服务器执行上述步骤

2.在dev10服务器执行,如下操作

ssh-copy-id dev11
ssh-copy-id dev12
ssh-copy-id dev13

把dev10的公钥信息添加到其他服务器的~/.ssh/authorized_keys内

[root@dev11 ~]# cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDQRjWUrCsO2BJLYP/5wj86+dNN/6XB8T/ydKrmr0SAKCPyVrQ+R+XyNlp2RSMKyjsr/KGP91TbBOqgsDFckFnVJfTj4MqI3dDrRO7wXoWgt1o3w/VuiiEaa/u4oizWq4Lm+YlINl7iJ7jkjIz57ILPUZmzX/WlvF6SFRrPFTbS02tP8njmlajXgkVIHsLMhu9OYRiViX3rIYkBMinzHCWdyo9q6//2Ds0jiZpO3aQ892Azd25DdN5H7K4Vbr8zByFBYUubqdTAQYsnyha2HTucUwazDNOcN2bKAcxBlgyqyQ7q0kPMuglwYjTQJMMqWK6AxoHCtm7VJ3cBpNya4qdsl18AAkMzyhkGJv1K5hTvM/yxG9aDFyHQC6mJ6d8G/+iONqR9JXGmgcwtT8Fb7PpbqYODYAA/gTd2wh7xmkeF37O/XykcYdBC48+h9jU8RbkCbmh53p3nOFMU/KdBEstsmdlmRmvuBVJkXa73ajIa1eXhIQdw3+mYUIF6sW1gQJs= root@dev11
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDHxArdo31gzprKQxHHaG3LPmM23X3tH5mgHmUH2YmECF3ZwYRPS/Gho83/ag/8WP/5M45ANUymhajJljkIhG2YCV5xF6tmJUCDm44TNRW4LE1fxzXKqVFzGJM7c4cCfM8AnUV2xoWK32jSqzAUf7/bxcAMsqkrwTNJL0QHi77mC62f5FiKCYsyE4nccMLizpziQgxm8FpKq3Q4RWImAilMcnit11/a6H4oEtXlRHIjxDC+lBWXOJ5li9EbWX2Jv5LG7JcoERkCsET4ud2M25Jd/eXhtF/YinIdfk0e3mNAqrqr+CWKwxeIZ9Ynw7yo+qnURocbpu5QBCvzCDME8on/E2ORhGxGYJnEzAt1LiTzbtGWCIqg+w5IocN20UKMHTfK8z0Hsf4BMfWCf7g47zwm/6ijGI7qhytIqagohdfIIymjri158BM2ub8cdkq7pn4Xv+kI+tbqHJnRgPQS2jtMPhEp3eisPjzYi5SOoMaG48GTiHMhClTYAyOMbOmnaos= root@dev10

这时dev10就可以SSH免密到其他服务器了,

如果dev11也想SSH免密到其他服务器,也用命令拷贝公钥信息即可。

三、测试

[root@dev10 ~]# ssh dev11
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun May 17 09:15:59 2020 from 192.168.0.101
[root@dev11 ~]# exit
注销
Connection to dev11 closed.
[root@dev10 ~]#

 

四、删除SSH免密

vi ~/.ssh/authorized_keys

删除对应行数据即可

 

你可能感兴趣的:(CentOS,CentOS,SSH,免密)