本博客翻译自
ssh远程登陆服务器,需要密码验证,频繁输入实在是麻烦。建立SSH Password-less(无密码登陆)就可以很方便的登陆。 假定我们有两台机器本地与远程
本地: SSH Client : 192.168.0.12
远程: SSH Remote Host : 192.168.0.11
Step 1: 本地建立 SSH-Kegen Keys (192.168.0.12)
打开terminal, 输入如下命令:
ssh-keygen -t rsa
效果如下
[tecmint@tecmint.com ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tecmint/.ssh/id_rsa): [Press enter key]
Created directory '/home/tecmint/.ssh'.
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Press enter key]
Your identification has been saved in /home/tecmint/.ssh/id_rsa.
Your public key has been saved in /home/tecmint/.ssh/id_rsa.pub.
The key fingerprint is:
5f:ad:40:00:8a:d1:9b:99:b3:b0:f8:08:99:c3:ed:d3 tecmint@tecmint.com
The key's randomart image is:
+--[ RSA 2048]----+
| ..oooE.++|
| o. o.o |
| .. . |
| o . . o|
| S . . + |
| . . . o|
| . o o ..|
| + + |
| +. |
+-----------------+
过程动图

Step 2 在远程服务器建立.ssh 文件夹 – 192.168.0.11
接着在terminal输入如下命令, 从本地 192.168.0.12 连接远程服务器 192.168.0.11 此例中使用sheena作为用户名,并将.ssh建立在其名下
ssh sheena@192.168.0.11 mkdir -p .ssh
效果如下
[tecmint@tecmint ~]$ ssh sheena@192.168.0.11 mkdir -p .ssh
The authenticity of host '192.168.0.11 (192.168.0.11)' can't be established.
RSA key fingerprint is 45:0e:28:11:d6:81:62:16:04:3f:db:38:02:la:22:4e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.11' (ECDSA) to the list of known hosts.
sheena@192.168.0.11's password: [Enter Your Password Here]
过程动图

Step 3: 上传本地的公钥至远程服务器 – 192.168.0.11
使用ssh从本地上传本地的公钥(id_rsa.pub) 上传到服务器192.168.0.11 在用户sheena的.ssh文件夹下, 并命名为authorized_keys
命令如下:
cat .ssh/id_rsa.pub | ssh sheena@192.168.0.11 'cat >> .ssh/authorized_keys'
效果如下
[tecmint@tecmint ~]$ cat .ssh/id_rsa.pub | ssh sheena@192.168.0.11 'cat >> .ssh/authorized_keys'
sheena@192.168.1.2's password: [Enter Your Password Here]
过程动图

Step 4: 在远程服务器添加权限,使其成为可执行文件
命令如下
ssh sheena@192.168.0.11 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
效果如下
[tecmint@tecmint ~]$ ssh sheena@192.168.0.11 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
sheena@192.168.0.11's password: [Enter Your Password Here]
过程动图

Step 5: 大功告成
尝试输入: [tecmint@tecmint ~]$ ssh sheena@192.168.0.11
过程动图
