我尝试使用 WinSCP 连接到服务器,并使用私钥进行身份验证。如果我使用 Putty,则此操作正常,但当我尝试使用 WinSCP 时,相同的密钥被拒绝。
我唯一做的事情就是在两个 GUI 中输入服务器 IP 和密钥路径。[编辑] 用户名是“ubuntu”,通过读取密钥,服务器以某种方式知道我是谁,以及要将我连接到哪个虚拟机。使用 putty 时我必须输入用户名,而使用 WinSCP 时我可以预先定义它,也可以输入它(我都试过了)。
我为这两个程序提供了相同的密钥路径,即 .ppk 格式。
以下是WinSCP的日志:
. 2017-05-17 14:31:16.592 --------------------------------------------------------------------------
. 2017-05-17 14:31:16.592 WinSCP Version 5.9.5 (Build 7441) (OS 10.0.14393 - Windows 10 Education)
. 2017-05-17 14:31:16.592 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2017-05-17 14:31:16.592 Log level: Normal
. 2017-05-17 14:31:16.592 Local account: DESKTOP-SJM9N7Q\Maxim Ott
. 2017-05-17 14:31:16.592 Working directory: C:\Program Files (x86)\WinSCP
. 2017-05-17 14:31:16.592 Process ID: 5464
. 2017-05-17 14:31:16.593 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe"
. 2017-05-17 14:31:16.593 Time zone: Current: GMT+2, Standard: GMT+1 (Mitteleuropäische Zeit), DST: GMT+2 (Mitteleuropäische Sommerzeit), DST Start: 26.03.2017, DST End: 29.10.2017
. 2017-05-17 14:31:16.593 Login time: Mittwoch, 17. Mai 2017 14:31:16
. 2017-05-17 14:31:16.593 --------------------------------------------------------------------------
. 2017-05-17 14:31:16.593 Session name: BWcloud (Site)
. 2017-05-17 14:31:16.593 Host name: 134.60.51.55 (Port: 22)
. 2017-05-17 14:31:16.593 User name: ubuntu (Password: No, Key file: Yes, Passphrase: No)
. 2017-05-17 14:31:16.593 Tunnel: No
. 2017-05-17 14:31:16.593 Transfer Protocol: SFTP (SCP)
. 2017-05-17 14:31:16.593 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2017-05-17 14:31:16.593 Disable Nagle: No
. 2017-05-17 14:31:16.593 Proxy: None
. 2017-05-17 14:31:16.593 Send buffer: 262144
. 2017-05-17 14:31:16.593 SSH protocol version: 2; Compression: No
. 2017-05-17 14:31:16.593 Bypass authentication: No
. 2017-05-17 14:31:16.593 Try agent: Yes; Agent forwarding: Yes; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2017-05-17 14:31:16.593 GSSAPI: Forwarding: Yes
. 2017-05-17 14:31:16.593 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2017-05-17 14:31:16.593 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2017-05-17 14:31:16.594 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2017-05-17 14:31:16.594 Simple channel: Yes
. 2017-05-17 14:31:16.594 Return code variable: Autodetect; Lookup user groups: Auto
. 2017-05-17 14:31:16.594 Shell: default
. 2017-05-17 14:31:16.594 EOL: LF, UTF: Auto
. 2017-05-17 14:31:16.594 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2017-05-17 14:31:16.594 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2017-05-17 14:31:16.594 SFTP Bugs: Auto,Auto
. 2017-05-17 14:31:16.594 SFTP Server: default
. 2017-05-17 14:31:16.594 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2017-05-17 14:31:16.594 Cache directory changes: Yes, Permanent: Yes
. 2017-05-17 14:31:16.594 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2017-05-17 14:31:16.594 DST mode: Unix
. 2017-05-17 14:31:16.594 --------------------------------------------------------------------------
. 2017-05-17 14:31:16.652 Looking up host "134.60.51.55" for SSH connection
. 2017-05-17 14:31:16.653 Connecting to 134.60.51.55 port 22
. 2017-05-17 14:31:16.654 We claim version: SSH-2.0-WinSCP_release_5.9.5
. 2017-05-17 14:31:16.705 Server version: SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
. 2017-05-17 14:31:16.705 We believe remote version has SSH-2 channel request bug
. 2017-05-17 14:31:16.705 Using SSH protocol version 2
. 2017-05-17 14:31:16.706 Have a known host key of type ssh-ed25519
. 2017-05-17 14:31:16.706 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2017-05-17 14:31:17.141 Server also has ecdsa-sha2-nistp256/ssh-dss/ssh-rsa host keys, but we don't know any of them
. 2017-05-17 14:31:17.142 Host key fingerprint is:
. 2017-05-17 14:31:17.142 ssh-ed25519 256 a2:45:9b:45:ad:68:ea:8a:0b:05:11:ba:35:90:fe:05
. 2017-05-17 14:31:17.142 Verifying host key ssh-ed25519 0x6641e29b54243c7f e2e3014a0c1e45e7 b94017d3c85a3c01 8fdefc62d9b8f8a8 ,0x2255cb2a9d0411d5 36a6ac88c8c4c1ae 5915495f9c173e86 80f4da883f7c5ef6 with fingerprint ssh-ed25519 256 a2:45:9b:45:ad:68:ea:8a:0b:05:11:ba:35:90:fe:05
. 2017-05-17 14:31:17.163 Host key does not match cached key 0x62233d6170d863d8 a7a81e45359c7ec8 b69ad50d6f17e557 b2fe0dd00daa8a7,0x4b98045184945b41 d62f352537b498b4 f527fee1247b451c 22d3e75d00b98db6
. 2017-05-17 14:31:17.163 Host key matches cached key
. 2017-05-17 14:31:17.163 Initialised AES-256 SDCTR client->server encryption
. 2017-05-17 14:31:17.163 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2017-05-17 14:31:17.163 Initialised AES-256 SDCTR server->client encryption
. 2017-05-17 14:31:17.163 Initialised HMAC-SHA-256 server->client MAC algorithm
. 2017-05-17 14:31:17.201 Reading key file "C:\Program Files\PuTTY\bwcloud.ppk"
! 2017-05-17 14:31:17.201 Using username "ubuntu".
. 2017-05-17 14:31:17.219 Server offered these authentication methods: publickey
. 2017-05-17 14:31:17.219 Offered public key
! 2017-05-17 14:31:17.221 Server refused our key
. 2017-05-17 14:31:17.271 Server refused our key
. 2017-05-17 14:31:17.271 Server offered these authentication methods: publickey
. 2017-05-17 14:31:17.271 Disconnected: No supported authentication methods available (server sent: publickey)
* 2017-05-17 14:31:17.329 (EFatal) Disconnected: No supported authentication methods available (server sent: publickey)
* 2017-05-17 14:31:17.329 Anmeldungsprotokoll (Siehe Sitzungsprotokoll für Details):
* 2017-05-17 14:31:17.330 Verwende Benutzername "ubuntu".
* 2017-05-17 14:31:17.330 Der entfernte Rechner lehnte unseren Schlüssel ab.
* 2017-05-17 14:31:17.330
* 2017-05-17 14:31:17.330 Anmeldung fehlgeschlagen.
[编辑] 这是我成功登录时的Putty日志文件:
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.05.17 17:04:17 =~=~=~=~=~=~=~=~=~=~=~=
login as: ubuntu
Authenticating with public key "imported-openssh-key"
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-75-generic x86_64)
* Documentation: https://help.ubuntu.com/
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
111 packages can be updated.
0 updates are security updates.
*** System restart required ***
Last login: Wed May 17 15:03:36 2017 from 134.60.66.119
]0;ubuntu@maxim: ~ubuntu@maxim:~$
这是我在服务器上看到的。我如何知道要访问哪个日志文件?此外,我应该查找什么?服务器上文件夹内容的屏幕截图
这是 Putty 事件日志:事件日志(我无法复制粘贴内容,抱歉!)
我打开了 auth.log 和 auth.log.1 文件,但那里的时间偏移了两个小时。不过,当我尝试使用 WinSCP 连接时,我认为这里没有保存任何内容。以下是最后几行。我使用 putty 连接,然后使用 WinSCP 尝试了几次,然后再次打开日志文件:
May 18 08:04:57 maxim sshd[27705]: Accepted publickey for ubuntu from 134.60.66.119 port 61014 ssh2: RSA SHA256:BKLucrkY+1+Gdk+Nxu4dB4YlyiF4Np22h/1wmmfkRm4
May 18 08:04:57 maxim sshd[27705]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
May 18 08:04:57 maxim systemd: pam_unix(systemd-user:session): session opened for user ubuntu by (uid=0)
May 18 08:04:57 maxim systemd-logind[651]: New session 430 of user ubuntu.
May 18 08:05:01 maxim CRON[27791]: pam_unix(cron:session): session opened for user root by (uid=0)
May 18 08:05:01 maxim CRON[27791]: pam_unix(cron:session): session closed for user root
May 18 08:14:19 maxim sshd[27705]: pam_unix(sshd:session): session closed for user ubuntu
May 18 08:14:19 maxim systemd-logind[651]: Removed session 430.
May 18 08:15:01 maxim CRON[27824]: pam_unix(cron:session): session opened for user root by (uid=0)
May 18 08:15:01 maxim CRON[27824]: pam_unix(cron:session): session closed for user root
May 18 08:17:01 maxim CRON[27829]: pam_unix(cron:session): session opened for user root by (uid=0)
May 18 08:17:01 maxim CRON[27829]: pam_unix(cron:session): session closed for user root
May 18 08:23:50 maxim sshd[27839]: Accepted publickey for ubuntu from 134.60.66.119 port 63162 ssh2: RSA SHA256:BKLucrkY+1+Gdk+Nxu4dB4YlyiF4Np22h/1wmmfkRm4
May 18 08:23:50 maxim sshd[27839]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
May 18 08:23:50 maxim systemd-logind[651]: New session 434 of user ubuntu.
May 18 08:23:50 maxim systemd: pam_unix(systemd-user:session): session opened for user ubuntu by (uid=0)
May 18 08:25:01 maxim CRON[27898]: pam_unix(cron:session): session opened for user root by (uid=0)
May 18 08:25:01 maxim CRON[27898]: pam_unix(cron:session): session closed for user root
非常感谢大家的建议!
你知道我下一步该做什么吗?我只想上传一些文件 :/
答案1
你是不是连接到同一主机。Putty 连接到 134.60.51。57而WinSCP连接到134.60.51。55。
此外,由于 SSH 主机密钥不同,它们实际上是不同的主机:
- 油灰:
ssh-ed25519 256 2e:d6:11:b3:…
- 温SCP:
ssh-ed25519 256 a2:45:9b:45:…
答案2
我收到了同样的错误消息,显然是由于其他原因。这是我找到的解决方案:
对于 WinSCP <= 5.19.x:在服务器(Linux)端,您需要将此行添加到 /etc/ssh/sshd_config:
PubkeyAcceptedAlgorithms +ssh-rsa
此问题应该已在 WinSCP 5.20+ 中修复。请参阅 WinSCP 官方帖子:https://winscp.net/tracker/1952 笔记:我正在运行 ArchLInux 服务器,但这对于基于 Fedora 或 Debian 的系统应该相同。
答案3
!2017-05-17 14:31:17.221 服务器拒绝我们的密钥
。2017-05-17 14:31:17.271 服务器拒绝我们的密钥
好吧,问问服务器。/var/log/*auth*log
在服务器上检查一下。
如果您无权访问这些文件,请考虑询问有权限的人。
确保你使用的是同一个密钥。我建议从命令行连接,并指定命令行,以帮助确保这一点。(使用-i
指定要使用的密钥;如果我没有记错的话,PuTTY 和 WinSCP 的密钥是一样的。)向我们展示使用的命令行。
当它与 PuTTY 一起工作时,您使用 ubuntu 的用户名登录?