勖日陽光 發表於 2022-8-5 09:02:00

银河麒麟服务器操作系统 V10 SP1 开启SSH服务

<div id="cnblogs_post_body" class="blogpost-body blogpost-body-html" style="font-size: 16px">
<h1>一、查看系统版本</h1>
<div class="cnblogs_code">
<pre><code class="has">nkvers</code></pre>
</div>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/958f96329d6e000bf1bef6f6f6fb5ab6.png">
</div>
<p></p>
<h1>二、首先,确定银河麒麟服务器操作系统安装了openssh</h1>
<div class="cnblogs_code">
<pre><code class="has">yum list installed | grep openssh</code></pre>
</div>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/f3332bedfee3f8e17e082ce7e32cc6ca.png">
</div>
<strong></strong>
<p></p>
<p>此处显示已经安装了openssh。<br> 如果此处没有任何输出显示,表示没有安装openssh</p>
<p>当发现没有安装openssh时,使下面的命令安装openssh:</p>
<div class="cnblogs_code">
<pre><code class="has">yum install openssh</code></pre>
</div>
<h1>三、确认开启sshd服务</h1>
<div class="cnblogs_code">
<pre><code class="has">systemctl status sshd</code></pre>
</div>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/a7d0a8e44b6ebb02987aabee11b26a69.png">
</div>
<p></p>
<p>如图所示,已经开启sshd服务。</p>
<p>如果显示未开启sshd服务,使用下列命令开启sshd服务</p>
<div class="cnblogs_code">
<pre><code class="has">systemctl start sshd</code></pre>
</div>
<h1>四、设置ssh服务开机启动</h1>
<p>使用下面的命令查看ssh服务是否开机启动</p>
<div class="cnblogs_code">
<pre><code class="has">systemctl is-enabled sshd</code></pre>
</div>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/a4a1b648df9d70308aae1c0bb6ef6c46.png">
</div>
<p></p>
<p>如上图所示,ssh已经默认开机启动</p>
<p>如果显示disabled,则使用下列命令设置ssh开机启动</p>
<p>systemctl enable sshd</p>
<h1>五、使用基于密钥的认证</h1>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为了更进一步的提高系统安全,可以生成 SSH 密钥对,然后强制使用基于密钥的认证,并禁用密码认证。要这样做,请在 vi 或者 nano 等文本编辑器中打开/etc/ssh/sshd_config 配置文件,并将 PasswordAuthentication 选项修改为如下内容: </p>
<div class="cnblogs_code">
<pre><code class="has">PasswordAuthentication no</code></pre>
</div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果您不是在一个新的默认安装的系统中进行操作,请检查配置文件确保没有设置 PubkeyAuthentication no 选项。如果是远程连接上的,而不是使用的控制台或者带外访问,建议在禁用密码认证之前先测试一下基于密钥的登录过程。 </p>
<h2>5.1、生成密钥对</h2>
<p>要生成 SSH 协议版本 2 的 RSA 密钥对,请按以下步骤操作: 1) 在 shell 命令行提示符下输入以下命令生成 RSA 密钥对: </p>
<p>1) 在 shell 命令行提示符下输入以下命令生成 RSA 密钥对:</p>
<div class="cnblogs_code">
<pre><code class="has">~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/USER/.ssh/id_rsa):</code></pre>
</div>
<p>2) 按回车键确认新创建的密钥的默认路径,即~/.ssh/id_rsa。</p>
<p> 3) 输入一个口令,并且在提示确认的时候再次输入该口令。为了安全起见,请不要使用和您登录您的账户相同的密码。 </p>
<p>4) 默认情况下,将~/.ssh/目录的权限设置为 rwx------或者以八进制标注表示的 700。这是为了确保只有对应的用户 USER 能够查看其内容。如果有必要,可以使用以下命令来进行确认:</p>
<div class="cnblogs_code">
<pre><code class="has"># ls -ld ~/.ssh
drwx------ 2 root root 617月5 16:40 /root/.ssh
#
</code></pre>
</div>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/e198a2591d9134d22415c29a58734d92.png">
</div>
<p></p>
<p>5)使用cp 命令复制id_rsa.pub 文件中公钥到 authorized_keys文件中,如果 authorized_keys 文件已经存在了,将密钥追加到该文件的末尾。</p>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/f5dd7b19a1bb9041ca6aea4ea6747088.png">
</div>
<p></p>
<h1>六、 使用xshell工具,SSH 协议进行远程连接</h1>
<p>通过U盘把私钥【id_rsa】文件复制到windows电脑。</p>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/0976e4890f179de95aa468e822a01c04.png">
</div>
<p></p>
<p></p>
<div style="text-align: center">
<img src="https://img-blog.csdnimg.cn/img_convert/a328f11446fd46db925a026945f37ec3.png">
</div>
<p></p>
<h1></h1>
</div><br><br>
来源:https://www.cnblogs.com/haolb123/p/16553002.html
頁: [1]
查看完整版本: 银河麒麟服务器操作系统 V10 SP1 开启SSH服务