2016-07-07 25 views
0

我試圖登錄到我的服務器拋出一個堡壘主機和我的配置文件是這樣的:SSH不能與「-F」合作,通過一個堡壘主機登錄

Host 10.10.10.1 
User ec2-user 
ProxyCommand ssh -W %h:%p xxx.xxx.xxx.xxx 
IdentityFile key.pem 

Host xxx.xxx.xxx.xxx 
User ec2-user 
IdentityFile key.pem 
ForwardAgent yes 

它工作正常,如果我救這個配置在〜/ .ssh中,名稱爲「config」,這是ssh的默認配置文件。我可以「的ssh -v 10.10.10.1」登錄和DEBUGLOG是這樣的:

OpenSSH_6.9p1, LibreSSL 2.1.8 
debug1: Reading configuration data ~/.ssh/config 
debug1: /Users/twer/.ssh/config line 2: Applying options for 10.10.10.1 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 21: Applying options for * 
debug1: Executing proxy command: exec ssh -W 10.10.10.1:22 xxx.xxx.xxx.xxx 
debug1: permanently_drop_suid: 501 
debug1: key_load_public: No such file or directory 
debug1: identity file key.pem type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file key.pem-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_6.9 
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 
debug1: Authenticating to 10.10.10.1:22 as 'ec2-user' 
... 

但是,如果我保存配置其他地方(刪除在〜/ .ssh的配置),並與「SSH登錄-v -F〜/ mysshconfig 10.10.10.1「,失敗。調試日誌是:

OpenSSH_6.9p1, LibreSSL 2.1.8 
debug1: Reading configuration data ansible-ssh.conf 
debug1: ansible-ssh.conf line 1: Applying options for 10.10.10.1 
debug1: Executing proxy command: exec ssh -W 10.10.10.1:22 xxx.xxx.xxx.xxx 
debug1: permanently_drop_suid: 501 
debug1: key_load_public: No such file or directory 
debug1: identity file key.pem type -1 
debug1: key_load_public: No such file or directory 
debug1: identity file key.pem-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_6.9 
Permission denied (publickey). 

因爲我想使用ansible,我需要用這個「-F」選項指定一個sshconfig。

回答

2

最後我想通了,我也應該指定在ProxyCommand配置文件,因爲它不是一個默認的。配置應該是這樣的:

Host 10.10.10.1 
User ec2-user 
ProxyCommand ssh ssh -F mysshconfig -W %h:%p xxx.xxx.xxx.xxx 
IdentityFile key.pem 

Host xxx.xxx.xxx.xxx 
User ec2-user 
IdentityFile key.pem 
ForwardAgent yes 
0

由於您的配置文件是在不同的位置,密鑰文件的相對路徑不再指向同一個地方,讓你得到「沒有這樣的文件」的錯誤時,SSH嘗試讀取密鑰文件。

使用,而不是一個絕對路徑:改變key.pem~/.ssh/key.pem

+0

謝謝,但它不是一個路徑問題。我已經搞清楚了。 – hsc