這篇文章將為大家詳細(xì)講解有關(guān)ssh怎么用,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、嘉魚網(wǎng)站維護(hù)、網(wǎng)站推廣。
本文以以下需求為背景,介紹詳細(xì)的做法:
需在同一臺(tái)服務(wù)器同時(shí)部署兩個(gè)不同的 Github 倉庫(對(duì) Bitbucket 等 git 服務(wù)同樣適用)
root 用戶可在遠(yuǎn)程登錄 SSH 后附上預(yù)期的 SSH Key 進(jìn)行 git 命令操作
nginx 用戶進(jìn)程(如 php-fpm)可在進(jìn)程內(nèi)附上預(yù)期的 SSH Key 進(jìn)行 git 命令操作
以 root 身份登錄服務(wù)器,為 root 用戶和 nginx 用戶分別生成 SSH Key。
倉庫 1:
$ ssh-keygen -b 2048 -t rsa -f "~/.ssh/id_rsa_github_myrepo1" $ sudo -u nginx ssh-keygen -b 2048 -t rsa -C "nginx@localhost" -f "/var/lib/nginx/.ssh/id_rsa_github_myrepo1"
倉庫 2:
$ ssh-keygen -b 2048 -t rsa -f "~/.ssh/id_rsa_github_myrepo2" $ sudo -u nginx ssh-keygen -b 2048 -t rsa -C "nginx@localhost" -f "/var/lib/nginx/.ssh/id_rsa_github_myrepo2"
此處的 nginx 用戶的主目錄因操作系統(tǒng)不同而擁有不同的路徑,經(jīng)測試 CentOS 系的操作系統(tǒng)可能值為:
"/var/lib/nginx" "/var/cache/nginx" "/usr/share/nginx"
之其一,請(qǐng)讀者執(zhí)行
sudo -u nginx ssh-keygen
查看并以實(shí)際路徑為準(zhǔn),替換本文中的對(duì)應(yīng)命令的路徑。如:
[root@localhost]# sudo -u nginx ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/var/cache/nginx/.ssh/id_rsa): 此處的 nginx 用戶的主目錄為 "/var/cache/nginx"。
將生成好的 SSH Key 的公鑰部分添加到兩個(gè) Github 倉庫設(shè)置的 Deploy Keys(部署密鑰)中。
倉庫 1:
$ cat "~/.ssh/id_rsa_github_myrepo1.pub" $ cat "/var/lib/nginx/.ssh/id_rsa_github_myrepo1.pub"
倉庫 2:
$ cat "~/.ssh/id_rsa_github_myrepo2.pub" $ cat "/var/lib/nginx/.ssh/id_rsa_github_myrepo2.pub"
編輯用戶的 SSH 配置文件,并指定主機(jī)的詳細(xì)自定義配置。
root 用戶:
$ nano "~/.ssh/config" Host github.com-myrepo1 HostName github.com User git IdentityFile ~/.ssh/id_rsa_github_myrepo1 Host github.com-myrepo2 HostName github.com User git IdentityFile ~/.ssh/id_rsa_github_myrepo2
nginx 用戶:
$ nano "/var/lib/nginx/.ssh/config" Host github.com-myrepo1 HostName github.com User git IdentityFile /var/lib/nginx/.ssh/id_rsa_github_myrepo1 Host github.com-myrepo2 HostName github.com User git IdentityFile /var/lib/nginx/.ssh/id_rsa_github_myrepo2
完成了上述步驟,讀者現(xiàn)在可以在 root 或 nginx 用戶登錄或以其運(yùn)行的進(jìn)程中執(zhí)行 git 命令,并且會(huì)自動(dòng)附上指定的 SSH Key。例如:
$ git clone git@github.com-myrepo1:tommy/myrepo1.git "/var/www/myrepo1" $ git clone git@github.com-myrepo2:tommy/myrepo2.git "/var/www/myrepo2"
<? header( 'Content-type: text/text' ); exit( shell_exec( 'cd /var/www/myrepo1; git pull origin master 2>&1' ) ); exit( shell_exec( 'cd /var/www/myrepo2; git pull origin master 2>&1' ) );
git remote set-url <name> <newurl> git remote set-url origin git@github.com-myrepo1:tommy/myrepo1.git git remote set-url origin git@github.com-myrepo2:tommy/myrepo2.git
刪掉,重新生成即可。
rm -f ~/.ssh/know_hosts ssh -T git@github.com Hi Anonymous! You've successfully authenticated, but Github.com does not provide shell access.
Bad owner or permissions sudo chmod 600 ~/.ssh/config
關(guān)于“ssh怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
當(dāng)前文章:ssh怎么用
分享URL:http://chinadenli.net/article6/jogdog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、網(wǎng)站設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、建站公司、靜態(tài)網(wǎng)站、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)