<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>SSH - Tag - 学习随记</title>
    <link>https://www.ronald.wang/tags/ssh/</link>
    <description>SSH - Tag - 学习随记</description>
    <generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Fri, 14 Oct 2022 12:00:33 &#43;0800</lastBuildDate><atom:link href="https://www.ronald.wang/tags/ssh/" rel="self" type="application/rss+xml" /><item>
  <title>centos7 openssh升级到最新版本</title>
  <link>https://www.ronald.wang/posts/linux/update_ssh/</link>
  <pubDate>Fri, 14 Oct 2022 12:00:33 &#43;0800</pubDate>
  <author>Ronald</author>
  <guid>https://www.ronald.wang/posts/linux/update_ssh/</guid>
  <description><![CDATA[<h3 id="注意事项">注意事项</h3>
<p>本文的环境都是系统自带的openssh，若是手动编译安装的，不保证成功。若是自带的，则升级过程中不需要卸载旧版本openssh。</p>
<p><strong>安装之前可以先试试yum更新,若是可以更新，就不需要往下看了</strong></p>
<pre tabindex="0"><code># centos8 $ yum update openssh -y # 重启sshd $ systemctl restart sshd 
</code></pre><h3 id="准备工作">准备工作</h3>
<h4 id="系统说明">系统说明</h4>
<ul>
<li>系统版本：CentOS Linux release 7.7.1908 (Core)</li>
<li>openssh：OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017</li>
<li>openssl: OpenSSL 1.0.2k-fips 26 Jan 2017</li>
</ul>
<h4 id="下载最新包">下载最新包</h4>
<ul>
<li><a href="https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/"target="_blank" rel="external nofollow noopener noreferrer">openssh</a></li>
<li><a href="https://ftp.openssl.org/source/?utm_source=hacpai.com"target="_blank" rel="external nofollow noopener noreferrer">openssl</a></li>
</ul>
<p>本文选择的是: openssh-8.2p1.tar.gz openssl-1.1.1g.tar.gz</p>
<pre tabindex="0"><code>$ wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz   $ wget https://ftp.openssl.org/source/openssl-1.1.1g.tar.gz 
</code></pre><h4 id="安装telnet备用可选">安装telnet备用（可选）</h4>
<p>安装新的ssh之后，只要配置好启动，就可以做到无缝切换，但是中途断开就不能连接了，为了防止这种情况，我们可以安装telnet当作备用，若是你能保证中途不会断开，此步骤可以忽略</p>
<p>1.安装</p>
<pre tabindex="0"><code>$ yum install telnet telnet-server -y 
</code></pre><p>2.启动</p>
<pre tabindex="0"><code>$ systemctl enable telnet.socket $ systemctl start telnet.socket 
</code></pre><p>3.连接</p>
<pre tabindex="0"><code># telnet 默认禁止root用户连接，我们先生成一个普通用户 $ useradd testuser $ passwd testuser   # 本地测试 $ telnet 127.0.0.1 VM_0_6_centos login: testuser Password: [testuser@VM_0_6_centos ~]$ # 切换root [testuser@VM_0_6_centos ~]$ su 
</code></pre><h3 id="升级openssl">升级openssl</h3>
<h4 id="备份">备份</h4>
<pre tabindex="0"><code>$ mv /usr/bin/openssl /usr/bin/openssl_old 
</code></pre><h4 id="安装">安装</h4>
<pre tabindex="0"><code>$ tar xzvf openssl-1.1.1g.tar.gz $ cd openssl-1.1.1g/ $ ./config shared &amp;&amp; make &amp;&amp; make install 
</code></pre><h4 id="配置软连接">配置软连接</h4>
<pre tabindex="0"><code>$ ln -s /usr/local/bin/openssl /usr/bin/openssl 
</code></pre><p>如果执行<code>openssl version</code>报下面的错误</p>
<pre tabindex="0"><code>openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory 
</code></pre><p>则执行下面命令解决：</p>
<pre tabindex="0"><code>$ ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/ $ ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/ 
</code></pre><p>旧版本:</p>
<pre tabindex="0"><code>$ openssl_old version OpenSSL 1.0.2k-fips  26 Jan 2017 
</code></pre><h3 id="升级openssh">升级openssh</h3>
<h4 id="安装所需依赖">安装所需依赖</h4>
<pre tabindex="0"><code>$ yum install zlib-devel  openssl-devel  pam-devel -y 
</code></pre><h4 id="备份-1">备份</h4>
<pre tabindex="0"><code>$ mkdir /etc/ssh_old $ mv /etc/ssh/* /etc/ssh_old/ 
</code></pre><h4 id="解压编译安装">解压、编译安装</h4>
<pre tabindex="0"><code>$ tar xzvf openssh-8.2p1.tar.gz $ cd openssh-8.2p1/   $ ./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/lib64/ --with-zlib --with-pam --with-md5-password --with-ssl-engine --with-selinux   # 安装 $ make &amp;&amp; make install   # 验证 $ ssh -V OpenSSH_8.2p1, OpenSSL 1.1.1g  21 Apr 2020   $ ls /etc/ssh moduli  ssh_config  sshd_config  ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key  ssh_host_ed25519_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub 
</code></pre><h4 id="配置">配置</h4>
<p>1.修改sshd_config</p>
<pre tabindex="0"><code>$ vim /etc/ssh/sshd_config   # 例子：配置root登录,   根据你以前的配置来 PermitRootLogin yes 
</code></pre><p>2.启动</p>
<pre tabindex="0"><code># 移走以前的ssh服务, 防止与新的冲突 $ mv /usr/lib/systemd/system/sshd.service /etc/ssh_old/sshd.service $ mv /usr/lib/systemd/system/sshd.socket /etc/ssh_old/sshd.socket   # 在解压包中拷贝一些文件 $ cp -a contrib/redhat/sshd.init /etc/init.d/sshd       # 重新启动 $ /etc/init.d/sshd restart $ systemctl daemon-reload   # 添加自启动 $ chkconfig --add sshd $ chkconfig sshd on 
</code></pre><h4 id="可能碰到的问题">可能碰到的问题：</h4>
<ol>
<li><code>/etc/init.d/sshd restart</code>之后报错</li>
</ol>
<pre tabindex="0"><code>Reloading systemd:                                         [  确定  ] Restarting sshd (via systemctl):  Job for sshd.service failed because the control process exited with error code. See &#34;systemctl status sshd.service&#34; and &#34;journalctl -xe&#34; for details.  [失败] 
</code></pre><p>是selinux导致，需要关闭</p>
<pre tabindex="0"><code># 临时修改 setenforce 0 # 永久修改 sed -i &#39;s/SELINUX=.*/SELINUX=disabled/g&#39; /etc/selinux/config # 重启 /etc/init.d/sshd restart 
</code></pre>]]></description>
</item>
</channel>
</rss>
