服务端安装并启动Openssh服务
1 2 3
| sudo apt-get update sudo apt-get install openssh-server sudo service ssh start
|
服务端授权客户端访问
1 2 3
| # 修改授权访问文件,若无此文件则新建 vim ~/.ssh/authorized_keys # 按行输入须授权的客户端ssh公钥即可
|
客户端配置公私钥对
1 2
| sudo ssh-keygen -t rsa -f ~/.ssh/id_rsa_xxx -C "..." sudo service ssh restart
|
添加客户端ssh公钥到服务器授权访问列表
1
| sudo ssh-copy-id -i ~/.ssh/id_rsa.pub user@server_ip
|
使用ssh进行免密登录
客户端配置n个Key访问n个服务
https://appkfz.com/2015/06/18/git-ssh-key/
多站点使用不同的ssh key
1 2 3 4 5 6 7 8
| Host company HostName company.com User git IdentityFile ~/.ssh/user1 Host github HostName github.com User git IdentityFile ~/.ssh/user2
|
同一站点使用不同的ssh key
1 2 3 4 5 6 7 8
| Host gitcafe-site1 HostName gitcafe.com User git IdentityFile ~/.ssh/user1 Host gitcafe-site2 HostName gitcafe.com User git IdentityFile ~/.ssh/user2
|
Q&A
ssh-add报错
case1
1
| Error connecting to agent: Connection refused
|
重启ssh-agent
1 2
| exec ssh-agent zsh eval `ssh-agent -s`
|
case2
1
| No user exists for uid 501
|
重启终端即可
多客户端SSH KEY
配置了多个KEY,但是jenkins验证失败,尝试重启jenkins所在的web服务器