OPENSSH 升级

captains 2021-07-20 PM 985℃ 0条

openssh.jpg

1、openssh注意事项

  • 升级过程会卸载openssh,连接窗口千万不要关闭,最好开2个连接窗口。
  • 永久关闭selinux
  • 离线升级所需包repo,在线升级不需要下载此包
    离线依赖包下载

2、下载openssh源码包

# 官网下载路径
https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
# 本次下载路径
https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

3、安装依赖包

$ yum install openssl-devel zlib-devel gcc gcc-c++ make -y

4、查找现有版本openssh的pid位置

# 做记录
$ find / -name sshd.pid

5、 卸载旧版openssh

# 卸载旧版openssh
$ rpm -e --nodeps $(rpm -qa|grep openssh)
# 移除旧版配置文件
$ mkdir /etc/ssh/bk && mv /etc/ssh/* /etc/ssh/bk/

6、上传openssh源码

$ pwd
/opt/soft
$ rz

7、解压&编译&安装

  • 编译注释说明
--prefix 安装目录
--sysconfdir 配置文件目录
--with-ssl-dir 指定 OpenSSL 的安装目录
--with-privsep-path 非特权用户的chroot目录
--with-privsep-user=sshd 指定非特权用户为sshd
--with-zlib 指定zlib库的安装目录
--with-md5-passwords 支持读取经过MD5加密的口令
--with-ssl-engine 启用OpenSSL的ENGINE支持
  • 安装
# 解压
$ cd /opt/soft
$ tar xf openssh-8.6p1.tar.gz
# 编译
cd openssh-8.6p1/
./configure --prefix=/usr/ --sysconfdir=/etc/ssh/ --with-ssl-dir=/usr/local/ssl --with-md5-passwords --mandir=/usr/share/man/
# 验证编译结果,返回值为0则成功
$ echo $?
0
# 安装
$ make && make install 

8、其他

# 删除/etc/ssh/下的密钥对, (只删除密钥对即可, 在重启的时候会重新生成), 此步省略!!!
rm -f /etc/ssh/ssh_host_*
# 复制启动文件至/etc/init.d/
$ cp -a contrib/redhat/sshd.init /etc/init.d/sshd
# 编辑/etc/init.d/sshd文件, 将PID_FILE改为之前记下的sshd.pid路径
$ vi /etc/init.d/sshd
# 设置开机启动sshd
chkconfig sshd on
chkconfig --list sshd
# 编辑/etc/ssh/sshd_config, 设置一些常用参数
vi /etc/ssh/sshd_config
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
AllowTcpForwarding yes
X11Forwarding yes
PidFile /run/sshd.pid
# 编辑/usr/lib/systemd/system/sshd.service, 添加以下内容
vi /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
#After=network.target sshd-keygen.service
#Wants=sshd-keygen.service
After=network.target
[Service]
#Type=notify
#EnvironmentFile=/etc/sysconfig/sshd
#ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecStart=/usr/sbin/sshd
#ExecReload=/bin/kill -HUP $MAINPID
#KillMode=process
#Restart=on-failure
#RestartSec=42s
[Install]
WantedBy=multi-user.target

9、启动ssh

# 编辑好这个配置文件之后进行以下操作
systemctl enable sshd
systemctl status sshd
systemctl restart sshd
systemctl status sshd

10、增加sshd配置信息

# sshd可能与xshell不兼容,增加以下配置
$ vim /etc/ssh/sshd_conf
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1
# 重启sshd
$ systemctl restart sshd
标签: LINUX

非特殊说明,本博所有文章均为博主原创。

评论啦~