我正在使用 Windows 计算机上的 OpenSSH 连接到 Linux Mint 9 框。我的 Windows 用户名与 ssh 目标的用户名不匹配,因此我尝试使用 指定用于登录的用户ssh_config
。我知道 OpenSSH 可以看到该ssh_config
文件,因为我在其中指定了标识文件。
ssh_config 中特定于主机的部分是:
Host hostname
HostName hostname
IdentityFile ~/.ssh/id_dsa
User username
Compression yes
如果我这么做ssh username@hostname
它就有效了。
尝试使用ssh_config
仅给出:
F:\>ssh -v hostname
OpenSSH_5.6p1, OpenSSL 0.9.8o 01 Jun 2010
debug1: Connecting to hostname [XX.XX.XX.XX] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /cygdrive/f/progs/OpenSSH/home/.ssh/id_rsa type -1
debug1: identity file /cygdrive/f/progs/OpenSSH/home/.ssh/id_rsa-cert type -1
debug1: identity file /cygdrive/f/progs/OpenSSH/home/.ssh/id_dsa type 2
debug1: identity file /cygdrive/f/progs/OpenSSH/home/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debia
n-3ubuntu5
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'hostname' is known and matches the RSA host key.
debug1: Found key in /cygdrive/f/progs/OpenSSH/home/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /cygdrive/f/progs/OpenSSH/home/.ssh/id_rsa
debug1: Offering DSA public key: /cygdrive/f/progs/OpenSSH/home/.ssh/id_dsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
我的印象是(正如这个问题所概述的:如何让 ssh 以正确的用户身份登录?) 指定User username
应该ssh_config
可以工作。
为什么 OpenSSH 不使用指定的用户名ssh_config
?
答案1
问题实际上是 OpenSSH 正在寻找~/.ssh/config
(扩展为/cygdrive/f/progs/OpenSSH/home/.ssh/config
) 处的配置,而不是 处的配置/cygdrive/f/progs/OpenSSH/etc/ssh_config
。
将设置放入~/.ssh/config
其中。
答案2
对于遇到此问题并被困在 Windows 上的人来说,cygwin 中 .ssh 文件夹位置的 Windows 等效项不是您在环境中指定的 $HOME 目录!cygwin openssh 使用的路径是 /home/username/.ssh :(
我的解决方法是删除 /home/username 目录,并将其符号链接到真正的主目录(“cd ~”切换到的目录)。祝你好运。
答案3
通常,自定义用户配置应该进入~/.ssh/config
而不是进入/etc/ssh/config
。/etc/ssh/config
是为了进行系统范围的更改。