SSH
默认的目录 ~/.ssh
公钥的权限可以开大点,私钥最好 600
部署公钥
- 创建公钥
ssh-keygen -t rsa -C "yourname@xxx.com"
- 将公钥加入到项目的部署公钥中
cat id_rsa.pub
- 测试生效
ssh -T git@git.coding.net #或者其他 git 网站
#成功显示
#Coding.net Tips : [Hello! You've connected to #Coding.net via SSH. This is a deploy key.]
#Connection to git.coding.net closed.
- 部署项目
使用 git 协议 克隆项目并部署
自动部署
将 公钥 录入 authorized_keys 文件中 并设置 权限 600
多会话管理
如果经常多会话,ssh到不同的服务器就需要用到ssh的配置管理
#配置目录 当前自己使用的电脑
vim ~/.ssh/config
# config 配置格式
Host 域名或别名
HostName 主机名
Port 端口
User 用户名
IdentityFile 密钥文件的路径
# 配置好之后 可以直接 使用 别名访问
ssh 域名或别名
#示列:
Host *.coding.net
IdentityFile ~/.ssh/id_rsa.coding
User cuihairu
Host github.com
IdentityFile ~/.ssh/github_rsa
User cuihairu
Host *.oschina.net
IdentityFile ~/.ssh/oschaina
User cuihairu
Host *.aliyun.com
IdentityFile ~/.ssh/ali
User cuihairu
# 如果需要自动登录到运程服务器
#需要将 公钥 加入到服务器的 需要登录的用户名 ~/.ssh/authorized_keys中
#保证权限正确
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys
#保证服务器端sshd开启PubkeyAuthentication
vim /etc/ssh/sshd_config
PubkeyAuthentication yes
#开启之后需要重启sshd