我正在 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
用於系統範圍的變更。