首页 > 解决方案 > 手动(物理)ssh-copy-id 到 windows 机器

问题描述

全部

回来的时候,我把一台旧的 Windows 电脑变成了服务器。我希望能够在不使用密码的情况下通过 SSH 连接。我不能使用ssh-copy-id,因为没有人记得密码。我试图手动将我的 ssh 公钥粘贴到其中C:\Users\user\.ssh\authorized_keys,但是当我这样做ssh -v user@$HOST时,仍然会提示我输入密码。这是输出:

(base) XXXXX@My-MacBook-Pro ~ % ssh -v XXXXX@XXX.XXX.XXX.XXX
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to XXX.XXX.XXX.XXX [XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug1: identity file /Users/XXXXX/.ssh/id_rsa type 0
debug1: identity file /Users/XXXXX/.ssh/id_rsa-cert type -1
debug1: identity file /Users/XXXXX/.ssh/id_dsa type -1
debug1: identity file /Users/XXXXX/.ssh/id_dsa-cert type -1
debug1: identity file /Users/XXXXX/.ssh/id_ecdsa type -1
debug1: identity file /Users/XXXXX/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/XXXXX/.ssh/id_ed25519 type -1
debug1: identity file /Users/XXXXX/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/XXXXX/.ssh/id_xmss type -1
debug1: identity file /Users/XXXXX/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_7.7
debug1: match: OpenSSH_for_Windows_7.7 pat OpenSSH* compat 0x04000000
debug1: Authenticating to XXX.XXX.XXX.XXX:22 as 'XXXXX'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:FfgvWKV3j7yQbkir5hFTe/JzYtXTHpmVZ2/8YqCCLas
debug1: Host 'XXX.XXX.XXX.XXX' is known and matches the ECDSA host key.
debug1: Found key in /Users/XXXXX/.ssh/known_hosts:4
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/XXXXX/.ssh/id_rsa RSA SHA256:9oWgqJ2MsMwSaR6AMNWnBkuacnVf7PkQSR+SG1Q6ptI
debug1: Will attempt key: /Users/XXXXX/.ssh/id_dsa 
debug1: Will attempt key: /Users/XXXXX/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/XXXXX/.ssh/id_ed25519 
debug1: Will attempt key: /Users/XXXXX/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/XXXXX/.ssh/id_rsa RSA SHA256:9oWgqJ2MsMwSaR6AMNWnBkuacnVf7PkQSR+SG1Q6ptI
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /Users/XXXXX/.ssh/id_dsa
debug1: Trying private key: /Users/XXXXX/.ssh/id_ecdsa
debug1: Trying private key: /Users/XXXXX/.ssh/id_ed25519
debug1: Trying private key: /Users/XXXXX/.ssh/id_xmss
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
XXXXX@XXX.XXX.XXX.XXX's password: 

.ssh一些论坛帖子声称这是目录和文件的权限问题authorized_keys(例如此处)。运行os.stat(使用 python)我们发现它authorized_keys有 666 个权限,但是 python 的 os.chmod不能完全适用于 windows,并且不清楚如何在 windows 中获得正确的数字权限,最好是通过命令行,因为 GUI 非常滞后和困难使用(最好是在 python 中,因为这是我最强的语言)。

Windows中的权限问题会是一个问题吗?如果是这样,正确的权限是什么?我们如何像在 UNIX(chmod)中那样更改它们?如果不是,那么导致 ssh 提示输入密码的问题可能是什么?

从技术上讲,我可以格式化并重新安装操作系统(或者最好安装 Linux),但我真的很想避免这种情况,因为服务器已经启动并运行。

标签: pythonwindowssshpublic-key

解决方案


推荐阅读