Ubuntu ssh 免密码登陆

1.生成密钥对

ubuntu@lxc-3:~$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): 
/home/ubuntu/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ubuntu/.ssh/id_rsa.
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.
The key fingerprint is:
47:1d:eb:60:9b:cf:9f:82:07:b0:60:4d:76:59:16:76 ubuntu@lxc-3
The key's randomart image is:
+--[ RSA 2048]----+
|           o*.E  |
|        o o+ +   |
|       + .+ o    |
|      o oo =     |
|     . .So+ .    |
|        ...o     |
|           oo    |
|          . o. . |
|           . .o  |
+-----------------+


2.将公钥放入公钥文件中

ubuntu@lxc-3:~/.ssh$ touch authorized_keys
ubuntu@lxc-3:~/.ssh$ cat id_rsa.pub >> authorized_keys 

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpzhhJojOT6RgajFf+8rsaUvJ38cMd6Jb/Y6aPYdWq3GJrVF0c6A6m58PWRQZuHQMU0QohEMU+I7YG9CbeZBRu9nxEzehVg37WI9tCr/nc4hMvAVnQ4R3IixtiaDeg6v6Kjy3qGFkrUu/XNc8e35TbgwgOE+xGnqWng4mNOKOzZgG5UrcLL4NyVNg12jwL+Ju+ii15M5za7H2whU40AmYQwXjWIS9QnTylj4LRJGwG26lOhOzrKhswibvl7sIFf+Fz0mXQ6MFbVlFCXX+RavJDAXu5+t9tmLHn9ENDBNodOPzLnvv+oJ9f2rY5aQO8zbJfaz9QZGzTRNVJF3sbFcS9 ubuntu@lxc-3


3.授权<必须>

ssh目录的权限必须是700,私钥和authorized_keys的权限必须时600

chmod 700 -R .ssh

chmod 600  authorized_keys

chmod 600 id_rsa



4.重启ssh服务<可选>

ubuntu@lxc-4:~/.ssh$ sudo service ssh restart

猜你喜欢

转载自blog.csdn.net/Jackie_Rose/article/details/50747253