我的文件中有以下配置值~/.ssh/config
:
Host *-lk
User root
Host beta-lk
Hostname beta.*****.com
Host accounts-lk
Hostname accounts.*****.com
Host demo-lk
Hostname demo.*****.com
Host central1-lk
Hostname central-api-1.*****.com
Host central2-lk
Hostname central-api-2.*****.com
User ubuntu
IdentityFile ~/.ssh/*****.aws.pem
今天刚刚创建central2-lk
。当我尝试 ssh 到central2-lk
主机时:
➜ ssh -v central2-lk
OpenSSH_7.4p1 Debian-10+deb9u3, OpenSSL 1.0.2l 25 May 2017
debug1: Reading configuration data /home/hjpotter92/.ssh/config
debug1: /home/hjpotter92/.ssh/config line 17: Applying options for *-lk
debug1: /home/hjpotter92/.ssh/config line 41: Applying options for central2-lk
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to central-api-2.*****.com [XXXX.XXX.XXX.XX] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/hjpotter92/.ssh/*****.aws.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/hjpotter92/.ssh/*****.aws.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to central-api-2.*****.com:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:3lqRdK0W0zOqWIW0bSkn9vMAFbXbEiRdY9cgcvDZ4ZM
debug1: Host 'central-api-2.*****.com' is known and matches the ECDSA host key.
debug1: Found key in /home/hjpotter92/.ssh/known_hosts:36
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/hjpotter92/.ssh/*****.aws.pem
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to central-api-2.*****.com ([XXXX.XXX.XXX.XX]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Remote: Port forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Forced command.
debug1: Sending environment.
debug1: Sending env LANG = en_IN
debug1: Sending env LC_CTYPE = en_IN
debug1: Sending env LC_ALL = en_IN.UTF-8
Please login as the user "ubuntu" rather than the user "root".
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to central-api-2.*****.com closed.
Transferred: sent 3204, received 3420 bytes, in 10.2 seconds
Bytes per second: sent 313.3, received 334.5
debug1: Exit status 0
%
➜ ssh ubuntu@central2-lk
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1013-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
140 packages can be updated.
2 updates are security updates.
*** System restart required ***
Last login: Tue Jul 31 17:45:39 2018 from XXXX.XX.XX.XXX
ubuntu@ip-172-31-20-247:~$ logout
Connection to central-api-2.*****.com closed.
为什么我的配置设置User ubuntu
被central2-lk
忽略?
答案1
这是因为您Host *-lk
的配置中有第一个条目。正如它所说man ssh-config
:
For each parameter, the first obtained value will be used.
(...)
PATTERNS
A pattern consists of zero or more non-whitespace characters, ‘*’ (a wildcard that matches zero or more char‐
acters), or ‘?’ (a wildcard that matches exactly one character). For example, to specify a set of declara‐
tions for any host in the ".co.uk" set of domains, the following pattern could be used:
Host *.co.uk