-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lijie67
committed
Dec 30, 2021
1 parent
59e7502
commit b71cebb
Showing
21 changed files
with
3,693 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="apple-mobile-web-app-capable" content="yes"> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="black"> | ||
<meta name="referrer" content="unsafe-url"> | ||
<meta name="google-site-verification" content="" /> | ||
|
||
<title>Use Ssh</title> | ||
<meta name="author" content="JIEL"> | ||
<meta name="description" content="hello world"> | ||
|
||
|
||
<meta property="og:title" content="Use Ssh"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | ||
<meta property="og:site_name" content="blog"/> | ||
<link href="/apple-touch-icon-precomposed.png" sizes="180x180" rel="apple-touch-icon-precomposed"> | ||
<link rel="alternate" href="/atom.xml" title="blog" type="application/atom+xml"> | ||
<link rel="stylesheet" href="/css/main.css"> | ||
<link rel="stylesheet" href="/css/disqusjs.css"> | ||
<link rel="icon" type="image/x-icon" href="/favicon.ico"> | ||
|
||
<!-- | ||
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.1.0/styles/default.min.css"> | ||
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.1.0/highlight.min.js"></script> | ||
<script>hljs.initHighlightingOnLoad();</script> --> | ||
|
||
|
||
<!-- Global site tag (gtag.js) - Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-159221418-2"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', 'UA-159221418-2'); | ||
</script> | ||
<script src="/js/disqus.js"></script> | ||
<meta name="generator" content="Hexo 5.4.0"></head> | ||
|
||
<body> | ||
<a id="top"></a> | ||
<div id="main"> | ||
<div class="main-ctnr"> | ||
<div class="behind"> | ||
<a href="/" class="back black-color"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg> | ||
</a> | ||
<div class="description"> | ||
hello world | ||
</div> | ||
</div> | ||
|
||
|
||
<article class="standard post"> | ||
<div class="title"> | ||
|
||
|
||
<h1 class="page-title"> | ||
Use Ssh | ||
</h1> | ||
|
||
|
||
|
||
</div> | ||
<div class="page-meta center"> | ||
<time datetime="2016-06-02T07:51:00.000Z" itemprop="datePublished"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather feather-calendar"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg> | ||
2016-06-02 | ||
</time> | ||
|
||
|
||
|
||
|
||
|
||
|
||
<div class="reading"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="feather feather-eye"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg> | ||
<span id="busuanzi_value_page_pv">…</span> | ||
</div> | ||
|
||
</div> | ||
<hr> | ||
|
||
<div class="picture-container"> | ||
|
||
</div> | ||
<p>记录ssh的使用</p> | ||
<h1 id="SSH的使用"><a href="#SSH的使用" class="headerlink" title="SSH的使用"></a>SSH的使用</h1><p>SSH是一种连接服务器的方式,使用SSH可以不必每次都输入用户名和密码</p> | ||
<h2 id="一、-Add-SSH-key-to-Github"><a href="#一、-Add-SSH-key-to-Github" class="headerlink" title="一、 Add SSH key to Github"></a>一、 Add SSH key to Github</h2><h3 id="Mac"><a href="#Mac" class="headerlink" title="Mac"></a>Mac</h3><h5 id="1-打开命令行工具,输入以下内容-替换你的邮箱名"><a href="#1-打开命令行工具,输入以下内容-替换你的邮箱名" class="headerlink" title="1. 打开命令行工具,输入以下内容,替换你的邮箱名"></a>1. 打开命令行工具,输入以下内容,替换你的邮箱名</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ssh-keygen -t rsa -C "your_email@example.com"</span><br><span class="line"></span><br></pre></td></tr></table></figure> | ||
<blockquote> | ||
<p><code>-t</code> : [rsa | dsa ] 加密类型,默认rsa</p> | ||
</blockquote> | ||
<blockquote> | ||
<p><code>-C</code> : 添加一个注释</p> | ||
</blockquote> | ||
<h5 id="2-生成SSH-KEY"><a href="#2-生成SSH-KEY" class="headerlink" title="2. 生成SSH-KEY"></a>2. 生成SSH-KEY</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Generating public/private rsa key pair.</span><br><span class="line">Enter file in which to save the key (/Users/you/.ssh/id_rsa):</span><br></pre></td></tr></table></figure> | ||
|
||
<blockquote> | ||
<p>第一步执行后会让你指定一个ssh key文件名,默认是id_rsa,这里我们不使用默认的,因为你可能不止一个git服务,可能你们公司使用了gitlab或者其它的,但如果你使用默认的待会可以直接跳过第<em><strong>4</strong></em>步</p> | ||
</blockquote> | ||
<p>输入文件名,需要带上目录</p> | ||
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/Users/you/.ssh/github_rsa</span><br><span class="line"></span><br></pre></td></tr></table></figure> | ||
|
||
<h5 id="3-提示你输入密码,不要输入直接按确定就可以"><a href="#3-提示你输入密码,不要输入直接按确定就可以" class="headerlink" title="3. 提示你输入密码,不要输入直接按确定就可以"></a>3. 提示你输入密码,不要输入直接按确定就可以</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Enter passphrase (empty for no passphrase): [Type a passphrase]</span><br><span class="line">Enter same passphrase again: [Type passphrase again]</span><br><span class="line"></span><br></pre></td></tr></table></figure> | ||
|
||
|
||
<h5 id="4-多个SSH-KEY"><a href="#4-多个SSH-KEY" class="headerlink" title="4.多个SSH-KEY"></a>4.多个SSH-KEY</h5><p>添加config文件</p> | ||
<p>进入<code>~/.ssh</code>目录,使用vi或者你喜欢的编辑器添加<code>config</code>文件,保存以下内容</p> | ||
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Host github.com</span><br><span class="line">HostName github.com</span><br><span class="line">PreferredAuthentications publickey</span><br><span class="line">IdentityFile ~/.ssh/github_rsa</span><br><span class="line"></span><br><span class="line"><span class="comment">#如果有多个的话继续添加</span></span><br><span class="line">Host gitlab.com</span><br><span class="line">HostName gitlab.com</span><br><span class="line">PreferredAuthentications publickey</span><br><span class="line">IdentityFile ~/.ssh/gitlab_rsa</span><br></pre></td></tr></table></figure> | ||
|
||
<h5 id="5-添加ssh-key-到你的github账号"><a href="#5-添加ssh-key-到你的github账号" class="headerlink" title="5. 添加ssh-key 到你的github账号"></a>5. 添加ssh-key 到你的github账号</h5><p>复制SSH-key</p> | ||
<p><code>$ pbcopy < ~/.ssh/github_rsa.pub</code></p> | ||
<p>添加到github账户,具体参考<a target="_blank" rel="noopener" href="https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/#platform-mac">官网教程</a></p> | ||
<h5 id="6-完成"><a href="#6-完成" class="headerlink" title="6. 完成"></a>6. 完成</h5><p>测试你的SSH链接是否成功</p> | ||
<p><code>$SSH -T git@github.com</code></p> | ||
<p>如果出现下面内容就是验证成功了</p> | ||
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Hi youname! You've successfully authenticated, but GitHub does not provide shell access.</span><br></pre></td></tr></table></figure> | ||
<p>修改你的git仓库,开始使用吧</p> | ||
<p><code>git remote set-url origin git@github.com:you/xxx.git</code></p> | ||
<h2 id="windows"><a href="#windows" class="headerlink" title="windows"></a>windows</h2><p>windows下请使用<a target="_blank" rel="noopener" href="http://www.softpedia.com/get/Programming/Other-Programming-Files/Cmder.shtml">Cmder</a>或者GitBash等命令行工具</p> | ||
<blockquote> | ||
<p>~/.ssh 等于 c:/Users/you/.ssh<br>复制命令 clip <</p> | ||
</blockquote> | ||
<h2 id="二、使用ssh公钥-私钥-实现免密码登录服务器"><a href="#二、使用ssh公钥-私钥-实现免密码登录服务器" class="headerlink" title="二、使用ssh公钥/私钥 实现免密码登录服务器"></a>二、使用ssh公钥/私钥 实现免密码登录服务器</h2><p>一般我们连线上服务器可能会经过一层或多层堡垒机,可以通过SSH生成后的公钥传到服务器上来实现免密码登录。</p> | ||
<p>假如有两台服务器A 登录 B</p> | ||
<p>A : 192.168.146.95</p> | ||
<p>B : 172.22.213.13</p> | ||
<h5 id="1-在A服务器上生成ssh-key"><a href="#1-在A服务器上生成ssh-key" class="headerlink" title="1.在A服务器上生成ssh-key"></a>1.在A服务器上生成ssh-key</h5><p><code>$ssh-keygen -t rsa -C "your_email@example.com"</code></p> | ||
<h5 id="2-将公钥传到B服务器-ssh-authorized-keys文件,使用scp-命令上传"><a href="#2-将公钥传到B服务器-ssh-authorized-keys文件,使用scp-命令上传" class="headerlink" title="2.将公钥传到B服务器.ssh/authorized_keys文件,使用scp 命令上传"></a>2.将公钥传到B服务器<code>.ssh/authorized_keys</code>文件,使用<code>scp</code> 命令上传</h5><p><code>scp ~/.ssh/id_rsa.pub 172.22.213.13:~/.ssh/authorized_keys</code></p> | ||
<h5 id="3-如果前面步骤都做完,那现在就可以无密码登录了"><a href="#3-如果前面步骤都做完,那现在就可以无密码登录了" class="headerlink" title="3.如果前面步骤都做完,那现在就可以无密码登录了"></a>3.如果前面步骤都做完,那现在就可以无密码登录了</h5><pre><code> ssh 172.22.213.13 | ||
Last login: Mon Jun 6 15:04:46 2016 from 192.168.146.95 | ||
</code></pre> | ||
<hr> | ||
<p>last</p> | ||
|
||
<hr> | ||
</article> | ||
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div> | ||
</div> | ||
<footer class="page-footer"></div> | ||
<div class="right-foot"> | ||
<div class="firstrow"> | ||
<a href="#top" target="_self"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up"><line x1="12" y1="19" x2="12" y2="5"></line><polyline points="5 12 12 5 19 12"></polyline></svg> | ||
</a> | ||
<!-- © eijil 2015-2021 --> | ||
</div> | ||
<!-- <div class="secondrow"> | ||
<a target="_blank" rel="noopener" href="https://frankenstein-ashen.now.sh/"> | ||
Guestbook | ||
</a> | ||
</div> --> | ||
</div> | ||
</div> | ||
</footer> | ||
<script src="/js/zoom-image.js"></script> | ||
<script type="text/javascript"> | ||
var imgArr = document.getElementsByTagName('img') | ||
for (var i = 0; i < imgArr.length; i += 1) { | ||
zoom(imgArr[i]) | ||
} | ||
|
||
// dropdown scripts | ||
function $(s) { return document.querySelector(s)} | ||
function $$(s) { return document.querySelectorAll(s) } | ||
var dropDownElArr = $$('.dropdown') | ||
for (var i = 0; i < dropDownElArr.length; i += 1) { | ||
dropDownElArr[i].addEventListener('click', function(event) { | ||
var content = this.querySelector('.dropdown-content') | ||
event.stopPropagation() | ||
if (content.className.indexOf('open') < 0) { | ||
content.classList.add('open') | ||
} else { | ||
content.classList.remove('open') | ||
} | ||
}) | ||
} | ||
document.body.addEventListener('click', function() { | ||
var dropDownContentElArr = $$('.dropdown-content') | ||
for (var i = 0; i < dropDownContentElArr.length; i += 1) { | ||
dropDownContentElArr[i].classList.remove('open') | ||
} | ||
}) | ||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.