(ecs还需配合远程机器.ssh/authorized_keys里追加本地id_rsa_xx.pub文本内容)
> ssh-keygen -t rsa -C "ecs0@aliyun.com" #提示rsa存放路径时id_rsa_ecs0
> ssh-keygen -t rsa -C "ecs1@aliyun.com" #提示rsa存放路径时id_rsa_ecs1
> ssh-keygen -t rsa -C "user1@github.com" #同上
> ssh-keygen -t rsa -C "user2@github.com" #同上
> vim ~/.ssh/config
#ecs0-prod-web
Host xx.xx.xx.xx
port 22
PreferredAuthentications publickey
IdentityFile ~/.ssh/ecs/id_rsa_ecs0
#ecs1-test-web
Host xx.xx.xx.xx
port 2233
PreferredAuthentications publickey
IdentityFile ~/.ssh/ecs/id_rsa_ecs1
#coding
Host e.coding.net
HostName e.coding.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/coding/id_rsa_coding
#github-user1
Host user1.github.com
HostName github.com
User user1
PreferredAuthentications publickey
IdentityFile ~/.ssh/github/id_rsa_github_u1
#github-user2
Host user2.github.com
HostName github.com
User user2
PreferredAuthentications publickey
IdentityFile ~/.ssh/github/id_rsa_github_u2
排查问题debug:
> ssh -T git@e.coding.net (校验)
> ssh git@e.coding.net -vT (debug模式)
> ssh -T -vvv git@e.coding.net (debug详细模式)
问题:cmd命令中ssh模式git pull正常但eclipse中始终错误
解决:
1.mac下另外新建启动脚本~/bin/eclipse.sh:
#!/bin/sh
export GIT_SSH="/usr/bin/ssh"
open -n /Applications/Eclipse.app
2.eclipse->General->Network...->SSH2设置:
SSH2 HOME: /Users/xxx/.ssh(指向.ssh根目录,多账户时必须为config文件所在目录,默认~/.ssh)
Private keys: id_rsa(私钥文件名)
3.使用~/bin/eclipse.sh脚本重启Eclipse即可
问题:debug下SSH连接无响应失败
解决:有可能ssh_config没有开启HostKeyAlgorithms ssh-rsa,ssh-dss
> vim /etc/ssh/ssh_config
Host *
GSSAPIAuthentication yes
# If this option is set to yes then remote X11 clients will have full access
# to the original X11 display. As virtually no X11 client supports the untrusted
# mode correctly we set this to yes.
ForwardX11Trusted yes
# Send locale-related environment variables
SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE
SendEnv XMODIFIERS
HostKeyAlgorithms ssh-rsa,ssh-dss
问题:Warning: Permanently added the RSA host key for IP address 'xx.xx.x.x' to the list of known hosts.
解决:chmod 700 ~/.ssh/id_rsa
> vim /etc/hosts
192.30.253.112 github.com
18.205.93.1 bitbucket.org
> /etc/init.d/networking restart
问题:Load key "~/.ssh/id_rsa": invalid format
解决:这是私钥的问题,一般不能手动编辑,可能多删除了最后一行回车键,如果不是则只能重新生成
问题:load pubkey "~/.ssh/id_rsa": invalid format
解决:这是公钥的问题,直接根据私钥重新生成一次:ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub
问题:github多个帐户公用同一台电脑ssh公钥冲突
解决:由于github限制公钥只能用在一个账户配置上,可以生成多个公钥配合用户名加以区分
> vim ~/.ssh/config:
#用户1 github
Host myname0.github.com
HostName github.com
User myname0
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
#用户2 github
Host myname1.github.com
HostName github.com
port 22
User myname1
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa1
Host xx.xx.ecs.ip
port 22
PreferredAuthentications publickey
IdentityFile ~/.ssh/by/esc/id_rsa
> vim ./myname0demo-project/.git/config
[remote "origin"]
url = git@myname0.github.com:myname0/demo.git
> vim ./myname1demo-project/.git/config
[remote "origin"]
url = git@myname1.github.com:myname1/demo.git