如何SSH密码到本地没有密码?

编辑:把完全做了什么

我需要没有密码SSH本地主机,通常的做法(与公共密钥)不起作用。

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的信息

 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 localhost得到结果

 $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: 

我做了以下3个步骤来创build密码lesslogin

 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 

发现了这个问题。

运行debugging服务器:

 $sshd -Dd 

我发现它无法读取auth_key

 $chmod 750 $HOME 

修复。

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

 chmod og-wx ~/.ssh/authorized_keys 

执行以下步骤

 ssh-keygen -t rsa -C "your_email@example.com" # Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pair. 

使用默认文件和空密码(只需在接下来的2个步骤中按Enter键)

 # start the ssh-agent in the background eval "$(ssh-agent -s)" # Agent pid 59566 ssh-add 

将〜/ .ssh / id_rsa.pub的内容复制到〜/ .ssh / authorized_keys

确保以下是权限

  ls -l .ssh/ total 20 -rw-r--r--. 1 swati swati 399 May 5 14:53 authorized_keys -rw-r--r--. 1 swati swati 761 Jan 12 15:59 config -rw-------. 1 swati swati 1671 Jan 12 15:44 id_rsa -rw-r--r--. 1 swati swati 399 Jan 12 15:44 id_rsa.pub -rw-r--r--. 1 swati swati 410 Jan 12 15:46 known_hosts 

另外,请确保.ssh目录的权限。 这也很重要

 drwx------. 2 swati swati 4096 May 5 14:56 .ssh 

正确和安全的做法是按照这里所说的复制密钥。

在其他情况下, sshpass可以很方便。

 sshpass -p raspberry ssh pi@192.168.0.145 

请记住,这是不安全的。 尽pipe在安全的环境中使用它并不是一个好主意,但它对于脚本编写,自动化testing是非常有用的。

这可以结合

 ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pi@192.168.0.145 

以避免确认问题,防止发生脚本。

同样,只有在不同的机器共享IP的开发系统中使用它,安全性并不重要。

https://ownyourbits.com/2017/02/22/easy-passwordless-ssh-with-sshh/

两个简单的步骤:

 ssh-keygen -t rsa <Press enter for each line> ssh-copy-id localhost 

input密码,你就完成了。

作为被接受的答案,如果你遇到问题的话

  Agent admitted failure to sign using the key. 

你需要

  ssh-add 

即使在遵循所有build议之后,我也面临同样的问题,但是发现问题在于gnome-keyring的干扰。

解:

  1. 去search,寻找“启动应用程序”
  2. 如果您看到“SSH密钥代理”,请取消选中该框
  3. 重新启动机器并连接到本地主机。