不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2013-01-09 14:11:36  修改时间:2024-03-27 09:50:46  分类:Linux基础  编辑

如果在本地需要有多个 ssh key (指私钥), 可以通过如下方法进行管理:

方式一:通过 ssh-add 命令通知 ssh-agent 管理这些 key (私钥)

hzak@B85RPI:~/.ssh$ ssh-add ~/.ssh/github_brobwind
Could not open a connection to your authentication agent.

ssh-agent运行着呢,why? 

[解决方案] 解决git bash中,添加私钥时,执行“ssh-add pathName”时出现报错:“Could not open a connection to your authentication agent.”

hzak@B85RPI:~/.ssh$ ssh-agent 
SSH_AUTH_SOCK=/tmp/ssh-B2BQngT8ulRb/agent.12305; export SSH_AUTH_SOCK;
SSH_AGENT_PID=12306; export SSH_AGENT_PID;
echo Agent pid 12306;

方式二:通过 ~/.ssh/config 文件进行管理

Host *.github.com
    IdentiftyFile ~/.ssh/github_brobwind
    User brobwind

这里可以看出如果通过 ssh 登录到 github.com 时会使用 ~/.ssh/github_brobwind 文件中的 private key,测试配置是否生效可通过如下命令:

hzak@B85RPI:~/.ssh$ ssh -T git@github.com
Hi brobwind! You've successfully authenticated, but GitHub does not provide shell access.

显示更加详细的信息可通过如下命令:

hzak@B85RPI:~/.ssh$ ssh -T -v git@github.com
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/hzak/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /home/hzak/.ssh/id_rsa type -1
debug1: identity file /home/hzak/.ssh/id_rsa-cert type -1
debug1: identity file /home/hzak/.ssh/id_dsa type -1
debug1: identity file /home/hzak/.ssh/id_dsa-cert type -1
debug1: identity file /home/hzak/.ssh/id_ecdsa type -1
debug1: identity file /home/hzak/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/hzak/.ssh/id_ed25519 type -1
debug1: identity file /home/hzak/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/hzak/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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: /home/hzak/.ssh/id_rsa
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_PAPER = en_US.UTF-8
debug1: Sending env LC_ADDRESS = en_US.UTF-8
debug1: Sending env LC_MONETARY = en_US.UTF-8
debug1: Sending env LC_NUMERIC = en_US.UTF-8
debug1: Sending env LC_TELEPHONE = en_US.UTF-8
debug1: Sending env LC_IDENTIFICATION = en_US.UTF-8
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_MEASUREMENT = en_US.UTF-8
debug1: Sending env LC_TIME = en_US.UTF-8
debug1: Sending env LC_NAME = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi brobwind! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3504, received 1480 bytes, in 0.5 seconds
Bytes per second: sent 7295.9, received 3081.6
debug1: Exit status 1

 

 

摘自:https://www.brobwind.com/archives/1251

 


我的一个 简单粗暴的 处理方式:

$ vim ~/.ssh/config

追加如下内容:

IdentityFile  ~/.ssh/id_rsa_wenjianbao
IdentityFile  ~/.ssh/id_rsa

系统会 挨个地去 尝试这些私钥文件