用ssh免密登录,但ssh无法登录, 怎么办?

       之前登录服务器时,都是采用账号密码方式登录的。最近玩免密登录,看了一下原理,于是就玩起来了。其实也简单,网上到处都是相关操作,但我搞了好几次, ssh免密一直失败,还是提醒ubuntu@localhost's password:, 最后发现是权限的问题, 来看看:

ubuntu@VM-0-15-ubuntu:~$ ssh localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
ubuntu@localhost's password: 
Permission denied, please try again.
ubuntu@localhost's password: 
Permission denied, please try again.
ubuntu@localhost's password: 
Permission denied (publickey,password).            // 要密码,不知道, 很蛋疼
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ ssh-keygen -t rsa         // 一路enter按下去,不要停
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): 
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:
SHA256:HuAsdG85+vxn3RLn5QreR9k/CSclzJnimhRTXjPToi8 ubuntu@VM-0-15-ubuntu
The key's randomart image is:
+---[RSA 2048]----+
|              .  |
|           . * . |
|    . o   o = B  |
|   . + o + + * . |
|    . o S + o o o|
|     . + + E +.o=|
|      . o o o.+B+|
|       o o .oooo*|
|        o..o. o+.|
+----[SHA256]-----+
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ cd .ssh 
ubuntu@VM-0-15-ubuntu:~/.ssh$ ls
id_rsa  id_rsa.pub
ubuntu@VM-0-15-ubuntu:~/.ssh$ cat id_rsa.pub >> authorized_keys
ubuntu@VM-0-15-ubuntu:~/.ssh$ ls
authorized_keys  id_rsa  id_rsa.pub
ubuntu@VM-0-15-ubuntu:~/.ssh$ 
ubuntu@VM-0-15-ubuntu:~/.ssh$ 
ubuntu@VM-0-15-ubuntu:~/.ssh$ 
ubuntu@VM-0-15-ubuntu:~/.ssh$ cd ..
ubuntu@VM-0-15-ubuntu:~$ chmod 700 .ssh         // 必须
ubuntu@VM-0-15-ubuntu:~$ chmod 600 .ssh/*       // 必须
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ ssh localhost          // 免密进入一层localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-91-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Last login: Sat Mar  3 08:51:40 2018 from 222.248.84.42
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ ssh localhost         // 免密进入二层localhost
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-91-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Last login: Sat Mar  3 08:56:32 2018 from 127.0.0.1
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ 
ubuntu@VM-0-15-ubuntu:~$ exit                  // 退出二层localhost
logout
Connection to localhost closed.
ubuntu@VM-0-15-ubuntu:~$ exit
logout
Connection to localhost closed.                // 退出一层localhost, 回归到原来的shell
ubuntu@VM-0-15-ubuntu:~$ 

        

       爬山去了, 多锻炼, 减减肥。

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值