首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在没有密码的情况下ssh到localhost?

如何在没有密码的情况下ssh到localhost?
EN

Stack Overflow用户
提问于 2011-09-16 10:34:08
回答 14查看 102.9K关注 0票数 71

编辑:原封不动地放入已完成的内容

我需要在没有密码的情况下使用SSH本地主机,通常的方法(使用公钥)不起作用。

代码语言:javascript
复制
user@PC:~$ rm -rf .ssh/*
user@PC:~$ ssh-keygen -t rsa > /dev/null 
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
user@PC:~$ ls .ssh/
id_rsa  id_rsa.pub
user@PC:~$ ssh-copy-id -i localhost 
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is f7:87:b5:4e:31:a1:72:11:8e:5f:d2:61:bd:b3:40:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
user@localhost's password: 
Now try logging into the machine, with "ssh 'localhost'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

user@PC:~$ ssh-agent $SHELL
user@PC:~$ ssh-add -L
The agent has no identities.
user@PC:~$ ssh-add 
Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
user@PC:~$ ssh-add -L
ssh-rsa ...MY KEY HERE

user@PC:~$ ssh-copy-id -i localhost 
user@localhost's password: 
Now try logging into the machine, with "ssh 'localhost'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

user@PC:~$ ssh localhost echo 'testing'
user@localhost's password: 

user@PC:~$ 

因此,正如您在最后一个命令中看到的,它仍然在询问密码!我怎么才能修复它呢?Ubuntu-10.04,OpenSSH_5.3p1

EDIT2:

添加一些关于sshd的信息

代码语言:javascript
复制
user@PC:~$ cat /etc/ssh/sshd_config | grep Authentication
# Authentication:
RSAAuthentication yes
PubkeyAuthentication yes
RhostsRSAAuthentication no
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
ChallengeResponseAuthentication no
# PasswordAuthentication yes

EDIT3:来自$ssh -vv本地主机的Ading结果

代码语言:javascript
复制
$ssh -vv localhost
...
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/identity
debug1: Offering public key: /home/user/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
user@localhost's password: 
EN

回答 14

Stack Overflow用户

回答已采纳

发布于 2013-05-20 22:28:55

我完成了以下3个步骤来创建无密码登录

代码语言:javascript
复制
1. ssh-keygen -t rsa
Press enter for each line 
2. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3. chmod og-wx ~/.ssh/authorized_keys 
票数 176
EN

Stack Overflow用户

发布于 2011-09-16 19:17:09

已经发现了这个问题。

使用调试功能运行服务器:

代码语言:javascript
复制
$sshd -Dd

我发现它无法读取auth_key

代码语言:javascript
复制
$chmod 750 $HOME

修好了。

票数 21
EN

Stack Overflow用户

发布于 2012-05-25 04:00:21

另一种可能的答案是: authorized_keys文件可能存在并且是可读的。但如果它是组或全局可写的,它仍然会提示输入密码。这个问题的答案是

代码语言:javascript
复制
chmod og-wx ~/.ssh/authorized_keys
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7439563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档