<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Ssh on ffff65535</title><link>https://blog.ffff65535.com/tags/ssh/</link><description>Recent content in Ssh on ffff65535</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Wed, 18 Oct 2023 00:00:00 +0800</lastBuildDate><atom:link href="https://blog.ffff65535.com/tags/ssh/index.xml" rel="self" type="application/rss+xml"/><item><title>Linux使用密钥登录并禁用密码登录</title><link>https://blog.ffff65535.com/posts/2023/10/18/linux-uses-key-logins-and-disables-password-logins/</link><pubDate>Wed, 18 Oct 2023 00:00:00 +0800</pubDate><guid>https://blog.ffff65535.com/posts/2023/10/18/linux-uses-key-logins-and-disables-password-logins/</guid><description>&lt;h5 id="生成密钥">生成密钥&lt;/h5>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 生成rsa密钥对&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ssh-keygen -t rsa
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Generating public/private rsa key pair.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Enter file in which to save the key &lt;span style="color:#f92672">(&lt;/span>/root/.ssh/id_rsa&lt;span style="color:#f92672">)&lt;/span>: &lt;span style="color:#75715e"># 直接enter&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Enter passphrase &lt;span style="color:#f92672">(&lt;/span>empty &lt;span style="color:#66d9ef">for&lt;/span> no passphrase&lt;span style="color:#f92672">)&lt;/span>: &lt;span style="color:#75715e"># 直接enter&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Enter same passphrase again: &lt;span style="color:#75715e"># 直接enter&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Your identification has been saved in /root/.ssh/id_rsa &lt;span style="color:#75715e"># 生成的私钥&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Your public key has been saved in /root/.ssh/id_rsa.pub &lt;span style="color:#75715e"># 生成的公钥&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h5 id="安装公钥">安装公钥&lt;/h5>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 进入公钥目录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cd /root/.ssh/
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 将公钥写入 /root/.ssh/authorized_keys文件&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cat id_rsa.pub &amp;gt;&amp;gt; authorized_keys
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h5 id="设置ssh权限防止无法登录">设置.ssh权限，防止无法登录&lt;/h5>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>chmod &lt;span style="color:#ae81ff">600&lt;/span> authorized_keys
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>chmod &lt;span style="color:#ae81ff">700&lt;/span> ~/.ssh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h5 id="设置ssh打开密钥登录功能">设置ssh打开密钥登录功能&lt;/h5>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>vim /etc/ssh/sshd_config
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 启用密钥验证&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>PubkeyAuthentication yes
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 关闭密码登录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>PasswordAuthentication no
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 允许root用户通过ssh登录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>PermitRootLogin yes
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="重启ssh服务">重启ssh服务&lt;/h1>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>sudo systemctl restart sshd
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h5 id="如果可以使用密码登录">如果可以使用密码登录&lt;/h5>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>cat /etc/ssh/sshd_config.d/50-cloud-init.conf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>PasswordAuthentication yes
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 将yes改为no 或者直接删除该文件(50-cloud-init.conf)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>PasswordAuthentication no
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Ubuntu使用git无法读取远程仓库</title><link>https://blog.ffff65535.com/posts/2023/01/24/ubuntu-git-pull-fatal-could-not-read-from-remote-repository/</link><pubDate>Tue, 24 Jan 2023 00:28:00 +0800</pubDate><guid>https://blog.ffff65535.com/posts/2023/01/24/ubuntu-git-pull-fatal-could-not-read-from-remote-repository/</guid><description>&lt;p>使用git pull时提示&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>kex_exchange_identification: Connection closed by remote host
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Connection closed by 20.205.243.166 port &lt;span style="color:#ae81ff">22&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>fatal: 无法读取远程仓库。 请确认您有正确的访问权限并且仓库存在。
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>或
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>fatal: Could not read from remote repository.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>可能是使用了网络代理导致的，可以使用443端口进行ssh连接
可参考一下链接进行处理
&lt;a href="https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port">https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port&lt;/a>&lt;/p></description></item></channel></rss>