Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ssh connect不使用配置中的标识_Ssh_Ssh Keys - Fatal编程技术网

ssh connect不使用配置中的标识

ssh connect不使用配置中的标识,ssh,ssh-keys,Ssh,Ssh Keys,我正在尝试设置到gitlab.com的ssh连接。我有相应的标识文件,如果我显式地使用它,它就会工作。但当我期望它从配置读取标识文件时失败了 这里有明确的用法: ssh -v -i /root/.ssh/reshop-deploy -T git@gitlab.com OpenSSH_7.4p1, OpenSSL 1.0.2k 26 Jan 2017 debug1: Reading configuration data /root/.ssh/config debug1: Reading conf

我正在尝试设置到gitlab.com的ssh连接。我有相应的标识文件,如果我显式地使用它,它就会工作。但当我期望它从配置读取标识文件时失败了

这里有明确的用法:

ssh -v -i /root/.ssh/reshop-deploy -T git@gitlab.com
OpenSSH_7.4p1, OpenSSL 1.0.2k  26 Jan 2017
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 1: Applying options for *
debug1: Connecting to gitlab.com [52.167.219.168] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/reshop-deploy type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/reshop-deploy-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
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 gitlab.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw
debug1: Host 'gitlab.com' is known and matches the ECDSA host key.
debug1: Found key in /root/.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: Trying private key: /root/.ssh/reshop-deploy
debug1: Authentication succeeded (publickey).
Authenticated to gitlab.com ([52.167.219.168]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: PTY allocation disabled.
Welcome to GitLab, XXXX!
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2880, received 2776 bytes, in 0.4 seconds
Bytes per second: sent 6778.9, received 6534.1
debug1: Exit status 0
这里是配置内容:

cat /root/.ssh/config 
Host gitlab
    Hostname gitlab.com
    User git
    IdentityFile ~/.ssh/reshop-deploy
    IdentitiesOnly yes

它似乎忽略了标识文件,但我不明白为什么。

您的
~/.ssh/config
配置以
主机gitlab
开始。这意味着它之后的所有配置指令,直到下一个
主机
行,只有当您在命令行中将服务器完全引用为“
gitlab
”时才会生效,例如,
ssh gitlab
。如果您还希望在执行
ssh gitlab.com
ssh时应用配置git@gitlab.com
,然后您需要将
主机
行更改为
主机gitlab gitlab.com

您的问题在这里。
ls -al /root/.ssh/
total 60
drwxr-x---  2 root root  4096 Apr 25 17:54 .
drwx------ 11 root root  4096 Apr 25 18:01 ..
-rw-------  1 root root  5024 Jun 13  2016 authorized_keys
-rw-------  1 root root   193 Apr 25 17:48 config
-rw-------  1 root root  1675 Dec  4  2015 id_rsa
-rw-r--r--  1 root root 13991 Apr 25 16:59 known_hosts
-rw-------  1 root root  3243 Apr 25 14:40 reshop-deploy
cat /root/.ssh/config 
Host gitlab
    Hostname gitlab.com
    User git
    IdentityFile ~/.ssh/reshop-deploy
    IdentitiesOnly yes