1. 在本机生成非对称密钥
1
[email protected]:~/.ssh$ ssh-keygen -t rsa

三个输入分别是公私钥文件名钥匙密码确认密码,直接回车生成密钥id_rsa,公钥id_rsa.pub

  1. 登录远程Server,在用户的主目录下建立.ssh文件夹,如存在,跳过这一步
1
2
[email protected]:~$ mkdir .ssh
[email protected]:~$ chmod 0700 .ssh
  1. 在本机上将生成的公钥传送到远程Server上面
1
[email protected]:~/.ssh$ scp id_rsa.pub [email protected]:~/.ssh/id_rsa.pub
  1. 登录远程Server,将公钥加入认证列表
1
2
[email protected]:~/.ssh$ touch authorized_keys2
[email protected]:~/.ssh$ cat id_rsa.pub >> authorized_keys2
  1. 最后回到本机,测试自动登录
1
[email protected]:~$ ssh remote-server.com