我已经做了一个新的用户和密钥,但是当我远程访问时,它要求密码,但我没有设置一个。我也重新做了三次检查。下面是我运行的命令和错误。有人能看到我创建键的命令有什么明显的错误吗?
useradd -m -d /home/webuser -s /bin/bash webuser
su webuser
ssh-keygen -t rsa
cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm id_rsa.pub
ssh webuser@ip_of_target_server
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/id_rsa ((nil)),
debug2: key: /root/.ssh/id_dsa ((nil)),
debug2: key: /root/.ssh/id_ecdsa ((nil)),
debug2: key: /root/.ssh/id_ed25519 ((nil)),
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/root/.ssh/id_rsa':
debug2: no passphrase given, try next key
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
发布于 2017-04-20 21:46:46
你搞混了很多事。
您没有为您创建的用户设置密码,因此它实际上不能使用密码登录,因此SSH不会要求它。
但是,当您创建SSH密钥时,您的密码会保护该密钥。当它试图连接到服务器时,它需要读取该密钥来验证您的身份,并因此请求密钥密码。
另外,当您将密钥添加到授权密钥时和尝试连接时,我遗漏了几个步骤(从操作方式来看,日志中没有实际指示),就像您添加到授权密钥中的密钥不是试图连接的机器上的密钥一样。
发布于 2017-04-20 21:49:51
你需要:
另外,您使用的ssh命令是什么?从“哪个用户”到“哪个用户”?如果试图将ssh转到另一台计算机的根帐户,还需要确保其sshd_config
文件具有PermitRootLogin yes
或WithoutPassword no
。
提醒:您生成的公钥需要部署在目标用户的authorized_key文件中。所以当你做一个
ssh -i /root/.ssh/id_rsa root@remote_machine
它在没有任何密码的情况下工作(如果在使用ssh-keygen -t rsa
时没有设置密码,它会提示您,并且您必须按两次enter,不要输入任何值)
希望这有帮助
而且,看起来您创建了一个名为webuser
的用户,但是您正在尝试从根用户执行ssh。恐怕行不通。您必须在特定用户中创建一个键区,并将公钥的内容部署到要针对的其他用户/机器。
https://serverfault.com/questions/845623
复制相似问题