Linux免密码登录

在服务器运维过程中,有时为了方便执行脚本,会设置免密码登录。

当然如果这个主机被攻破,那么其他主机也就乖乖投降了。

完成免密登录,主要使用两个命令:

第一个:生成公钥

ssh-keygen

Generating public/private key pair.
Enter file in which to save the key (/ceph-admin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /ceph-admin/.ssh/id_rsa.
Your public key has been saved in /ceph-admin/.ssh/id_rsa.pub.

tips:使用git时候,根据后台设置,有些操作需要公钥,此时也需要生成公钥。

默认的Windows的公钥地址是“C:Users[SomeOne].sshid_rsa.pub",默认的Linux公钥地址在“~/.ssh/id_rsa.pub”

第二个:把公钥复制到其他服务器

ssh-copy-id root@node1

其中node1是目标主机,可以是ip地址,也可以是域名。

原文地址:https://www.cnblogs.com/bugutian/p/11058440.html