日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

【运维】Linux 系统 之 SSH

發(fā)布時間:2025/6/15 linux 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【运维】Linux 系统 之 SSH 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

前言

Secure Shell(安全外殼協(xié)議,簡稱SSH)是一種加密的網(wǎng)絡(luò)傳輸協(xié)議,可在不安全的網(wǎng)絡(luò)中為網(wǎng)絡(luò)服務(wù)提供安全的傳輸環(huán)境。SSH通過在網(wǎng)絡(luò)中創(chuàng)建安全隧道來實現(xiàn)SSH客戶端與服務(wù)器之間的連接。雖然任何網(wǎng)絡(luò)服務(wù)都可以通過SSH實現(xiàn)安全傳輸,SSH最常見的用途是遠程登錄系統(tǒng),人們通常利用SSH來傳輸命令行界面和遠程執(zhí)行命令。 --- wiki百科

公鑰私鑰對

使用 ssh-keygen 創(chuàng)建 id_rsa 和 id_rsa.pub

ssh-keygen -t rsa -C "your_email@example.com" [hostname ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/admin/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/admin/.ssh/id_rsa. Your public key has been saved in /home/admin/.ssh/id_rsa.pub. The key fingerprint is:

步驟解說

輸入步驟1:
Enter file in which to save the key (/home/admin/.ssh/id_rsa)
設(shè)置保存公鑰的地址

輸入步驟2:
Enter passphrase (empty for no passphrase):
設(shè)置公鑰密碼, 默認為空, 如果設(shè)置了則需要修改連接方式 ssh -K xxx

輸入步驟3:
Enter same passphrase again:
重復(fù)設(shè)置公鑰密碼

結(jié)束后會生成 id_rsa (私鑰)和 id_rsa.pub (公鑰) 兩個文件

正文

使用場景

- 遠程服務(wù)器1連接遠程服務(wù)器2 - 本地拉取遠程GIT代碼 - 腳本部署代碼

遠程服務(wù)器連接

假設(shè)我現(xiàn)在有兩臺服務(wù)器

  • 服務(wù)器A 10.0.0.1
  • 服務(wù)器B 10.0.0.2

若想要服務(wù)器A能夠不用密碼登錄服務(wù)器B,則需要把服務(wù)器A的 id_rsa.pub 加入服務(wù)器B某個用戶的authorized_keys, 然后執(zhí)行 ssh b@10.0.0.2

第一次用服務(wù)器a連接服務(wù)器b 是都會有一段 finger 驗證

The authenticity of host '10.0.0.2 (10.0.0.2)' can't be established. RSA key fingerprint is 70:e5:23:cf:dc:03:2d:09:40:4a:2a:c6:c5:17:e2:32. Are you sure you want to continue connecting (yes/no)?

意圖是要將服務(wù)器b的公鑰存放在服務(wù)器a的 ~/.ssh/know_hosts 文件里面

# 忽略輸入yes/no ssh -o StrictHostKeyChecking=no b@10.0.0.2

本地拉取遠程GIT代碼

假設(shè)有以下幾臺機器

  • 本地機器 local
  • 遠程機器 git

以github為例, 我們將本地及其 地址為: https://github.com/settings/s...
圖片如下:

我們在客戶端機器上生成的 id_rsa.pub 填寫至這個表單中, 這就表示github的倉庫允許我們用戶去拉取代碼。

腳本部署代碼

假設(shè)我們使用ssh-keygen生成一組deploy的(deploy_id_rsa.pub)公鑰,(deploy_id_rsa)私鑰。 具體執(zhí)行方式

# deploy.sh# 手動開啟ssh eval $(ssh-agent -s) # 添加deploy私鑰 ssh-add ./deploy_id_rsa # 查看ssh-agent中的密鑰 ssh-add -l # 從ssh-agent 刪除 deploy密鑰, 需要依靠 deploy公鑰 ssh-add -d ./deploy_id_rsa.pubexport deploy_server=b@10.0.0.2 export deploy_path=/home/www/webrootssh -o StrictHostKeyChecking=no -P22 ${deploy_server} "mkdir -p ${deploy_path}/public" ssh -o StrictHostKeyChecking=no -P22 ${deploy_server} "mkdir -p ${deploy_path}/_tmp" scp -P22 -r build/* ${deploy_server}:${deploy_path}/_tmp ssh -p22 ${deploy_server} "mv ${deploy_path}/public ${deploy_path}/_old && ${deploy_path}/_tmp ${deploy_path}/public" ssh -p22 server_user@server_host "rm -rf ${deploy_path}/_old"

上述腳本的作用就是將build的所有內(nèi)容傳輸?shù)?服務(wù)器b 的/home/www/webrrot/public里面

小結(jié)

作者目前使用的道德ssh相關(guān)情況為以上幾種情況, 但ssh的作用遠不止上述列的幾項。等到升入了解后再補充該文。 歡迎大家留言提問,及點贊收藏 !!

總結(jié)

以上是生活随笔為你收集整理的【运维】Linux 系统 之 SSH的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。