在本地跳板机上执行ssh-keygen -t rsa -P ''

[root@c160 ~]# ssh-keygen -t rsa -P ''

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Created directory '/root/.ssh'.

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:

0a:ff:31:85:fc:80:e0:00:ff:29:53:b6:22:e2:37:66 root@c160

The key's randomart image is:

+--[ RSA 2048]----+

|.                |

| o               |

|  o +            |

|   * + o .       |

|o + * . S .      |

|o. + o . +       |

| . E  o o .      |

|  + .  . o       |

|        .        |

+-----------------+

生成公钥id_rsa.pub和密钥id_rsa,默认路径在/root/.ssh下面,其他用户在/home/username/.ssh下面,分发公钥id_rsa.pub到目标机器上,如:

scp id_rsa.pub root@10.20.1.2:/root/.ssh/authorized_keys
chmod 700 /root/.ssh/ -R 
chmod 600 /root/.ssh/authorized_keys

现在就可以ssh root@10.20.1.2 直接跳到10.20.1.2机器上了;
如果要登陆本机,默认是不能登陆的(即本机ssh登陆本机)直接将公钥id_rsa.pub导入到authorized_keys文件中即可

 cat ~/.ssh/id_rsa.pub >>  ~/.ssh/authorized_keys

如果是其他用户ssh免密码登陆,直接更换用户名即可;

带符号 * 的表示必填项