Github、Gitee同时配置SSH
<h3 id="1-进入ssh目录">1. 进入ssh目录</h3><p><code>cd ~/.ssh</code></p>
<h3 id="2-使用命令分别创建两个平台的公钥">2. 使用命令分别创建两个平台的公钥</h3>
<pre><code>ssh-keyen -t rsa -C "xxxxxx@xxx.com" -f "id_rsa_gitee"
ssh-keyen -t rsa -C "xxxxxx@xxx.com" -f "id_rsa_github"
</code></pre>
<p>完成后,目录内容如下:</p>
<pre><code>-rw------- 1 lambda lambda 1679 Jun 14 10:51 id_rsa_gitee
-rw-r--r-- 1 lambda lambda400 Jun 14 10:51 id_rsa_gitee.pub
-rw------- 1 lambda lambda 1679 Apr1 13:44 id_rsa_github
-rw-r--r-- 1 lambda lambda399 Apr1 13:44 id_rsa_github.pub
-rw-r--r-- 1 lambda lambda 2434 Jun 14 11:05 known_hosts
</code></pre>
<h3 id="3-将产生的公钥xxxpub内容分别配置到github和gitee">3. 将产生的公钥xxx.pub内容分别配置到Github和Gitee。</h3>
<h3 id="4-创建config文件解决ssh冲突">4. 创建config文件,解决SSH冲突</h3>
<p>在.ssh目录下创建config文件,添加如下内容:</p>
<pre><code># github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
</code></pre>
<h3 id="5-测试">5. 测试</h3>
<p>命令:</p>
<pre><code>ssh -T git@gitee.com
# 或
ssh -T git@github.com
</code></pre>
<p>成功:</p>
<pre><code>Hi xxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
</code></pre>
<h3 id="6-遇到问题">6. 遇到问题</h3>
<p>在测试环节,有时会出现如下错误:</p>
<pre><code># Linux
Bad owner or permissions on /home/lambda/.ssh/config
# Windows
Bad owner or permissions on C:\\Users\\Ran\\.ssh\\config
</code></pre>
<hr>
<p>解决办法</p>
<ul>
<li>Linux <br></li>
</ul>
<pre><code>sudo chmod 600 ~/.ssh/config
</code></pre>
<ul>
<li>Windows <br></li>
</ul>
<pre><code>1. 查看PATH环境中是否存在C:\Windows\System32\OpenSSH\ssh.exe <br>
2. 将C:\Windows\System32\OpenSSH\ssh.exe改成C:\Program Files\Git\usr\bin\ssh.exe <br>
</code></pre>
<h3 id="参考">参考</h3>
<blockquote>
<p>https://blog.csdn.net/weixin_36191602/article/details/80946242<br>
https://stackoverflow.com/questions/49926386/openssh-windows-bad-owner-or-permissions</p>
</blockquote><br><br>
来源:https://www.cnblogs.com/lambdaRan/p/11022857.html
頁:
[1]