红联Linux门户
Linux帮助

Ubuntu 14.04.2 LTS SSH无密码登陆配置

发布时间:2016-06-25 09:53:54来源:linux网站作者:CrazyL-

1、在用户主目录下mkdir .ssh
因为/etc/ssh/sshd_config中 AuthorizedKeysFile默认值是”.ssh/authorized_keys”。
AuthorizedKeysFile存放该用户可以用来登录的 RSA/DSA 公钥。
该指令中可以使用下列根据连接时的实际情况进行展开的符号:
%% 表示’%’、%h 表示用户的主目录、%u 表示该用户的用户名。
经过扩展之后的值必须要么是绝对路径,要么是相对于用户主目录的相对路径。
默认值是”.ssh/authorized_keys”。


2、在.ssh目录下执行ssh-keygen -t rsa
ubuntu1@master:~/.ssh$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ubuntu1/.ssh/id_rsa.
Your public key has been saved in /home/ubuntu1/.ssh/id_rsa.pub.
The key fingerprint is:
a6:15:be:f5:cd:45:f6:7b:80:18:47:37:6e:da:e2:d4 ubuntu1@master
The key’s randomart image is:
+–[ RSA 2048]—-+
| . o |
| . o . |
| … o o|
| . . + * o.|
| S o = E o|
| + o + + o.|
| . . o o..|
| .|
| |
+—————–+

ubuntu1@master:~/.ssh$ ll
total 16
drwxrwxr-x 2 ubuntu1 ubuntu1 4096 Jan 30 13:58 ./
drwxr-xr-x 17 ubuntu1 ubuntu1 4096 Jan 30 13:57 ../
-rw——- 1 ubuntu1 ubuntu1 1679 Jan 30 13:58 id_rsa
-rw-r–r– 1 ubuntu1 ubuntu1 396 Jan 30 13:58 id_rsa.pub


3、执行命令cat id_rsa.pub >> authorized_keys
将公钥信息保存到authorized_keys中
ubuntu1@master:~/.ssh$ chmod 644 authorized_keys


4、完成ssh无密码登陆配置
ubuntu1@master:~/.ssh$ ssh localhost
The authenticity of host ‘localhost (127.0.0.1)’ can’t be established.
ECDSA key fingerprint is b8:f0:bc:fb:79:1a:1e:d4:6b:6e:dd:75.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘localhost’ (ECDSA) to the list of known hosts.
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-30-generic x86_64)

Documentation: https://help.ubuntu.com/

Last login: Sat Jan 30 13:54:04 2016 from localhost


本文永久更新地址:http://www.linuxdiyf.com/linux/21816.html