首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ssh空白密码,但仍然要求

ssh空白密码,但仍然要求
EN

Server Fault用户
提问于 2017-04-20 21:20:57
回答 2查看 15.6K关注 0票数 6

我已经做了一个新的用户和密钥,但是当我远程访问时,它要求密码,但我没有设置一个。我也重新做了三次检查。下面是我运行的命令和错误。有人能看到我创建键的命令有什么明显的错误吗?

代码语言:javascript
运行
复制
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).
EN

回答 2

Server Fault用户

回答已采纳

发布于 2017-04-20 21:46:46

你搞混了很多事。

您没有为您创建的用户设置密码,因此它实际上不能使用密码登录,因此SSH不会要求它。

但是,当您创建SSH密钥时,您的密码会保护该密钥。当它试图连接到服务器时,它需要读取该密钥来验证您的身份,并因此请求密钥密码。

另外,当您将密钥添加到授权密钥时和尝试连接时,我遗漏了几个步骤(从操作方式来看,日志中没有实际指示),就像您添加到授权密钥中的密钥不是试图连接的机器上的密钥一样。

票数 3
EN

Server Fault用户

发布于 2017-04-20 21:49:51

你需要:

  • 确保您的目标.ssh文件夹具有正确的权限(通常为700),并且不要打开太大的权限(例如,不是775或其他)
  • 确保您的目的地authorized_keys也有正确的权限(通常为644)
  • 确保您的源私钥有正确的权限(600,最大)
  • 确保您的源和目的地主目录具有正确的权限(再次打开)
  • 确保authorized_keys中的键没有空格或换行符(cat不应该是这种情况)
  • 确保在执行ssh/scp/sftp时使用正确的私钥(默认情况下应该使用id_rsa )

另外,您使用的ssh命令是什么?从“哪个用户”到“哪个用户”?如果试图将ssh转到另一台计算机的根帐户,还需要确保其sshd_config文件具有PermitRootLogin yesWithoutPassword no

提醒:您生成的公钥需要部署在目标用户的authorized_key文件中。所以当你做一个

代码语言:javascript
运行
复制
ssh -i /root/.ssh/id_rsa root@remote_machine

它在没有任何密码的情况下工作(如果在使用ssh-keygen -t rsa时没有设置密码,它会提示您,并且您必须按两次enter,不要输入任何值)

希望这有帮助

而且,看起来您创建了一个名为webuser的用户,但是您正在尝试从根用户执行ssh。恐怕行不通。您必须在特定用户中创建一个键区,并将公钥的内容部署到要针对的其他用户/机器。

票数 2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/845623

复制
相关文章

相似问题

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