ssh无密登陆localhost

来源:互联网 发布:特别纳税调整 知乎 编辑:程序博客网 时间:2024/05/23 12:02
1、安装ssh
sudo apt-get ssh install

2、生成密钥
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
3、将公钥放入认证文件
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
4、修改文件权限
sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub
sudo chmod 644 ~/.ssh/authorized_keys

显示如下:
drwxr-xr-x  2 will will 4096 May 31 22:42 .
drwxr-xr-x 31 will will 4096 May 31 22:22 ..
-rw-------  1 will will  393 May 31 22:42 authorized_keys
-rw-------  1 will will 1679 May 31 22:42 id_rsa
-rw-------  1 will will  393 May 31 22:42 id_rsa.pub
-rw-r--r--  1 will will  666 May 31 08:41 known_hosts

此处假设.ssh的父目录是xxx  .ssh的路径   /home/xxx/.ssh
sudo chmod 755 /home/xxx  (我就是因为没有设置该文件夹的权限弄了很久都没成功!)

5、测试

ssh localhost


xxx@ubuntu:/$ ssh localhost
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-25-generic x86_64)
* Documentation:  https://help.ubuntu.com/
361 packages can be updated.
208 updates are security updates.
New release '16.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Wed May 31 22:59:20 2017 from localhost
xxx@ubuntu:~$ exit
logout
Connection to localhost closed.