SSH
默認的目錄 ~/.ssh
公鑰的權限可以開大點,私鑰最好 600
部署公鑰
- 創(chuàng)建公鑰
ssh-keygen -t rsa -C "yourname@xxx.com"
- 將公鑰加入到項目的部署公鑰中
cat id_rsa.pub
- 測試生效
ssh -T git@git.coding.net #或者其他 git 網(wǎng)站
#成功顯示
#Coding.net Tips : [Hello! You've connected to #Coding.net via SSH. This is a deploy key.]
#Connection to git.coding.net closed.
- 部署項目
使用 git 協(xié)議 克隆項目并部署
自動部署
將 公鑰 錄入 authorized_keys 文件中 并設置 權限 600
多會話管理
如果經(jīng)常多會話,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