<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Jun Sun - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ freeCodeCamp 是一个免费学习编程的开发者社区，涵盖 Python、HTML、CSS、React、Vue、BootStrap、JSON 教程等，还有活跃的技术论坛和丰富的社区活动，在你学习编程和找工作时为你提供建议和帮助。 ]]>
        </description>
        <link>https://www.freecodecamp.org/chinese/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Jun Sun - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/chinese/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 26 May 2026 04:21:39 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/chinese/news/author/aemoz/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ SSH Keygen 教程——如何为 RSA 登录生成 SSH 公钥 ]]>
                </title>
                <description>
                    <![CDATA[ 密码学中使用加密和解密来隐藏原始信息。这为信息安全带来了保密性。 加密技术的目的是确保通过不安全渠道连接的两个人或设备之间的通信安全。 发送者通常使用加密密钥来加密信息，而接收者使用解密密钥来解密信息。 一般来说，密码学采用两种策略：  1. 对称密钥加密（私钥）：      这种技术，使用的加密密钥和解密密钥对于发送方、接收方都是已知的。使用这种方式的有一次性密码、Vernam密码、Playfair、行列密码和数据加密标准（DES）。            2. 非对称密钥加密（公钥）：      使用此技术，每个人都有两个密钥：私钥（保密，只有创建者才能使用）和公钥（任何人都可以自由使用）。发送方和接收方使用不同的密钥进行加密和解密。使用该技术的一些算法示例包括     Rivest–Shamir–Adleman算法（RSA）、Diffie–Hellman密钥交换（DHE）和数字签名算法（DSA）。           安全数据传输的加密模型软件工程师通常必须通过服务器或GitHub等其他服务进行身份验证才能进行版本控制。 与使用密码身份验证相反，他们可以使用公钥身份验 ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/ssh-keygen-how-to-generate-an-ssh-public-key-for-rsa-login/</link>
                <guid isPermaLink="false">65f80b6a823801041102dee3</guid>
                
                    <category>
                        <![CDATA[ 网络安全 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jun Sun ]]>
                </dc:creator>
                <pubDate>Mon, 18 Mar 2024 10:03:43 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2024/03/block-and-stream-cipher.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>原文：</strong> <a href="https://www.freecodecamp.org/news/ssh-keygen-how-to-generate-an-ssh-public-key-for-rsa-login/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">SSH Keygen Tutorial – How to Generate an SSH Public Key for RSA Login</a>
      </p><!--kg-card-begin: markdown--><p>密码学中使用加密和解密来隐藏原始信息。这为信息安全带来了保密性。</p>
<p>加密技术的目的是确保通过不安全渠道连接的两个人或设备之间的通信安全。</p>
<p>发送者通常使用加密密钥来加密信息，而接收者使用解密密钥来解密信息。</p>
<p>一般来说，密码学采用两种策略：</p>
<ol>
<li>
<p><strong>对称密钥加密（私钥）：</strong> 这种技术，使用的加密密钥和解密密钥对于发送方、接收方都是已知的。使用这种方式的有一次性密码、Vernam密码、Playfair、行列密码和数据加密标准（DES）。</p>
</li>
<li>
<p><strong>非对称密钥加密（公钥）：</strong> 使用此技术，每个人都有两个密钥：私钥（保密，只有创建者才能使用）和公钥（任何人都可以自由使用）。发送方和接收方使用不同的密钥进行加密和解密。使用该技术的一些算法示例包括 Rivest–Shamir–Adleman算法（RSA）、Diffie–Hellman密钥交换（DHE）和数字签名算法（DSA）。</p>
</li>
</ol>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2022/06/Cryptography--2-.png" alt="安全数据传输的加密模型" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>安全数据传输的加密模型</figcaption>
</figure>
<p>软件工程师通常必须通过服务器或GitHub等其他服务进行身份验证才能进行版本控制。</p>
<p>与使用密码身份验证相反，他们可以使用公钥身份验证在计算机上生成并存储一对加密密钥。然后，他们可以将运行在另一台计算机上的服务器配置为识别并接受这些密钥。</p>
<p>这是我们前面讨论的非对称密钥加密技术流程，它是一个更安全的身份验证过程。</p>
<p>在本教程中，你将了解这一切是如何工作的，SSH的含义，以及如何使用SSH keygen生成使用RSA算法的SSH密钥。</p>
<h2 id="">先决条件</h2>
<ul>
<li>在任何操作系统上运行的工作计算机</li>
<li>熟悉命令行的基本操作</li>
<li>面带微笑：）</li>
</ul>
<h2 id="sshsecureshellprotocol">SSH 简介（Secure Shell Protocol)</h2>
<p>使用SSH的公钥身份验证是一种比密码更安全的登录服务方法。一旦你从上面的介绍中了解了密码学是如何工作的，那么理解SSH就更容易了。</p>
<p>以下是一个基本定义：</p>
<blockquote>
<p>“Secure Shell协议是一种加密网络协议，用于在不安全的网络上安全地运行网络服务。”（<a href="https://www.wikiwand.com/zh-sg/Secure_Shell">来源</a>）</p>
</blockquote>
<p>SSH在客户端和服务器之间使用，两者都在SSH协议上运行，以远程登录到服务器并通过命令行访问某些资源。</p>
<figure class="kg-card kg-card-image kg-card-hascaption">
    <img src="https://www.freecodecamp.org/news/content/images/2022/06/image-197.png" alt="来源：SSH Academy" class="kg-image" width="600" height="400" loading="lazy">
    <figcaption>来源：SSH Academy</figcaption>
</figure>
<p>SSH协议有一个开源版本（版本2），其中包含一套称为OpenSSH（也称为OpenBSD Secure Shell）的工具。此项目包括以下工具：</p>
<ul>
<li>远程操作：<a href="https://man.openbsd.org/ssh.1">ssh</a>、<a href="https://man.openbsd.org/scp.1">scp</a> 和 <a href="https://man.openbsd.org/sftp.1">sftp</a>.</li>
<li>密钥生成：<a href="https://man.openbsd.org/ssh-add.1">ssh-add</a>、<a href="https://man.openbsd.org/ssh-keysign.8">ssh-keysign</a>、<a href="https://man.openbsd.org/ssh-keyscan.1">ssh-keyscan</a> 和 <a href="https://man.openbsd.org/ssh-keygen.1"><strong>ssh-keygen</strong></a></li>
<li>服务端：<a href="https://man.openbsd.org/sshd.8">sshd</a>、<a href="https://man.openbsd.org/sftp-server.8">sftp-server</a> 和 <a href="https://man.openbsd.org/ssh-agent.1">ssh-agent</a></li>
</ul>
<h2 id="rsassh">如何为 RSA 登录生成 SSH 公钥</h2>
<p>我们的目标是使用 ssh-keygen 使用 RSA 算法生成 SSH 公钥。这将创建一个密钥对，其中包含私钥（保存到本地计算机）和公钥（上传到所选服务）。</p>
<p>现在要继续，请按照以下步骤实现此目的：</p>
<p>如果你尚未安装OpenSSH，请使用以下命令安装OpenSSH：</p>
<pre><code>// for mac

brew install openssh

// for linux

sudo apt install openssh-client &amp;&amp; sudo apt install openssh-server
</code></pre>
<p>2. 使用以下命令使用 RSA 算法（默认为 2046 位加密）创建私钥/公钥对：</p>
<pre><code>ssh-keygen -t rsa
</code></pre>
<p>3. 或者，如果要使用具有 4096 位加密的 RSA 算法进行创建，请使用以下命令：</p>
<pre><code>ssh-keygen -t rsa -b 4096
</code></pre>
<p>4. 输入要将密钥保存到的文件位置（默认情况下，它将保存到你的用户目录（例如，<code>(/Users/bolajiayodeji/.ssh/id_rsa)</code>）。</p>
<p>5. 输入密码短语以提高私钥的安全性。通常，一个好的密码短语应至少包含 15 个字符（包括至少一个大写字母、小写字母、数字和特殊字符），并且必须难以猜测。你可以在线使用这些密码生成器之一，也可以使用十六进制转储轻松生成释义，如下所示：</p>
<pre><code>hexdump -vn16 -e'4/4 "%08X" 1 "\n"' /dev/urandom
</code></pre>
<p>6. 成功创建密码后，你的私钥将保存在<code>/&lt;your_chosen_directory&gt;/.ssh/id_rsa</code>中，你的公钥将保存在<code>/&lt;your_chosen_directory&gt;/.ssh/id_rsa.pub</code>中。</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/Screenshot-2022-08-30-at-1.18.15-PM.png" alt="Screenshot-2022-08-30-at-1.18.15-PM" width="600" height="400" loading="lazy"></p>
<p>现在，你可以使用ssh-copy-id（此工具是openSSH的一部分）将创建的密钥复制到要连接的服务器的authorized_keys文件中，如下所示：</p>
<pre><code>ssh-copy-id username@remote_host
</code></pre>
<p>或者，你希望将 SSH 私钥添加到 ssh 代理中，并将密码存储在钥匙串中。然后，你可以通过仪表板 UI 等将 SHH 密钥添加到服务器的帐户中（例如，使用 Git 或 GitHub 等工具）。</p>
<h2 id="">结语</h2>
<p>尽管强密码有助于防止暴力攻击，但公钥身份验证使用加密技术提供了更安全的身份验证过程。</p>
<p>希望这篇文章对你有所帮助。此外，你可以查看<a href="https://man.openbsd.org/ssh-keygen.1">ssh-keygen手册页</a>和以下资源以进行进一步学习：</p>
<ul>
<li><a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh">Connecting to GitHub with SSH</a></li>
<li><a href="https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse">Get started with OpenSSH for Windows</a></li>
</ul>
<p>加油！💙</p>
<!--kg-card-end: markdown--> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
