首先创建密钥
ssh-keygen 创建公钥和密钥。
ssh-copy-id 把本地主机的公钥复制到远程主机的authorized_keys文件上。
ssh-copy-id 也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh/authorized_keys设置合适的权限 。
注意权限
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
步骤1: 用 ssh-keygen 在本地主机上创建公钥和密钥
ssh-keygen -t rsa # 然后一直按 [Enter] 键
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press Enter key]
Enter same passphrase again: [Pess Enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is: 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9
ll /root/.ssh/ # 在用户的家目录$home/.ssh/ 路径下就会有2个文件生成,id_rsa私钥,id_rsa.pub公钥
-rw------- 1 root root 1671 1月 19 14:59 id_rsa
-rw-r--r-- 1 root root 401 1月 19 14:59 id_rsa.pub
步骤2: 用 ssh-copy-id