第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

【運維】Linux 系統(tǒng) 之 SSH

標簽:
Linux 安全

前言

Secure Shell(安全外壳协议,简称SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境。SSH通过在网络中创建安全隧道来实现SSH客户端与服务器之间的连接。虽然任何网络服务都可以通过SSH实现安全传输,SSH最常见的用途是远程登录系统,人们通常利用SSH来传输命令行界面和远程执行命令。 --- wiki百科

公钥私钥对

使用 ssh-keygen 创建 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)
设置保存公钥的地址

输入步骤2:
Enter passphrase (empty for no passphrase):
设置公钥密码, 默认为空, 如果设置了则需要修改连接方式 ssh -K xxx

输入步骤3:
Enter same passphrase again:
重复设置公钥密码

结束后会生成 id_rsa (私钥)和 id_rsa.pub (公钥) 两个文件

正文

使用场景

- 远程服务器1连接远程服务器2- 本地拉取远程GIT代码- 脚本部署代码

远程服务器连接

假设我现在有两台服务器

  • 服务器A 10.0.0.1

  • 服务器B 10.0.0.2

若想要服务器A能够不用密码登录服务器B,则需要把服务器A的 id_rsa.pub 加入服务器B某个用户的authorized_keys,  然后执行 ssh b@10.0.0.2

第一次用服务器a连接服务器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)?

意图是要将服务器b的公钥存放在服务器a的 ~/.ssh/know_hosts 文件里面

# 忽略输入yes/nossh -o StrictHostKeyChecking=no b@10.0.0.2

本地拉取远程GIT代码

假设有以下几台机器

  • 本地机器 local

  • 远程机器 git

以github为例,
图片如下:

https://img1.sycdn.imooc.com//5af808ba000126fb06950407.jpg

我们在客户端机器上生成的 id_rsa.pub 填写至这个表单中, 这就表示github的仓库允许我们用户去拉取代码。

脚本部署代码

假设我们使用ssh-keygen生成一组deploy的(deploy_id_rsa.pub)公钥,(deploy_id_rsa)私钥。 具体执行方式

# deploy.sh# 手动开启ssheval $(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.2export deploy_path=/home/www/webroot

ssh -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的所有内容传输到 服务器b/home/www/webrrot/public里面


作者: wayneli                   
来源:https://segmentfault.com/a/1190000014766752?utm_source=channel-hottest



點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消