debian系统升级ssh

debian系统升级openssh

最近护网行动开始了,公司的老的服务器开始修补漏洞,今天我修补的漏洞是openssh。
OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。而实现此功能的传统方式,如telnet(终端仿真协议)、 rcp ftp、 rlogin、rsh都是极为不安全的,并且会使用明文传送密码。OpenSSH提供了服务端后台程序和客户端工具,用来加密远程控制和文件传输过程中的数据,并由此来代替原来的类似服务。

#首先我们看下自己服务器的ssh版本,现在最新版本是8.6

root@hecs-x-medium-2-linux-20210317100343:/opt# ssh -V
OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1d  10 Sep 2019

root@hecs-x-medium-2-linux-20210317100343:/opt# vim updatessh.sh

#将下面内容依次执行也可以,或者复制在脚本中执行,切记脚本执行报错就不要执行第二次,脚本报错就开始排查脚本执行到哪步报错,然后解决报错的问题依次执行脚本下面内容即可
##### openssh升级到8.6命令
# 安装依赖
apt-get install -y aptitude
aptitude install -f libpam0g-dev libselinux1-dev
apt-get install -y libssl-dev  zlib1g-dev

# 备份ssh配置
cp -rf /etc/ssh /etc/ssh.bak

# 设置文件权限
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key

# 配置sshd配置
sed -i 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^GSSAPICleanupCredentials/#&/' /etc/ssh/sshd_config
sed -i 's/^UsePAM/#&/' /etc/ssh/sshd_config

# 配置service, 取消notify
sed -i 's/^Type/#&/' /lib/systemd/system/ssh.service

# 下载包

wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
tar zxf openssh-8.6p1.tar.gz

# 编译安装
cd openssh-8.6p1
./configure --prefix=/usr --with-privsep-path=/var/empty/sshd/ \
       --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl/ \
       --with-default-path=/usr/local/bin:/bin:/usr/bin \
       --with-superuser-path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin \
       --with-pam --with-selinux --disable-strip --with-md5-passwords
make
make install

# 重启服务
systemctl daemon-reload

systemctl restart sshd

# 现在版本
ssh -V
root@hecs-x-medium-2-linux-20210317100343:/opt# bash updatessh.sh

#执行脚本最后成功的标志是ssh变成8.5,因为脚本最后的ssh -V就是返回当前ssh的版本号,我记得我上次离职的时候公司正在升级8.5的版本,我今天升级的8.1,明天过去给升级成8.5,今天在我的服务器已经测试了。

root@hecs-x-medium-2-linux-20210317100343:/opt# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1d  10 Sep 2019
# 以下是我执行中报错的解决方式
configure: error: *** zlib.h missing - please install first or check config.log ***
make: *** No targets specified and no makefile found.  Stop.
make: *** No rule to make target 'install'.  Stop.


报错1:configure: error: *** zlib.h missing - please install first or check config.log ***

解决方式:
apt install zlib1g-dev -y

报错2:configure: error: *** working libcrypto not found, check config.log
解决方式:
apt install openssl
apt install libssl-dev
报错3:
apt-get install aptitude
aptitude install libssl-dev

#升级中出现的错误解决
##### openssh升级到8.1命令
# 安装依赖
apt-get install -y aptitude
aptitude install -f libpam0g-dev libselinux1-dev
apt-get install -y libssl-dev  zlib1g-dev

# 备份ssh配置
cp -rf /etc/ssh /etc/ssh.bak1

# 设置文件权限
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key

# 配置sshd配置
sed -i 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^GSSAPICleanupCredentials/#&/' /etc/ssh/sshd_config
sed -i 's/^UsePAM/#&/' /etc/ssh/sshd_config

# 配置service, 取消notify
sed -i 's/^Type/#&/' /lib/systemd/system/ssh.service

# 下载包
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
tar zxf openssh-8.6p1.tar.gz

# 编译安装 openssh
cd openssh-8.6p1
./configure --prefix=/usr --with-privsep-path=/var/empty/sshd/ \
       --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl/ \
       --with-default-path=/usr/local/bin:/bin:/usr/bin \
       --with-superuser-path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin \
       --with-pam --with-selinux --disable-strip --with-md5-passwords 

make
make install

#  编译openssh 报错 C compiler cannot create executables 
apt --fix-broken install 
apt-get install gcc
# Yes, I say !
# dpkg 修复
apt-get download libc-bin
dpkg -x libc-bin*.deb unpackdir/
cp unpackdir/sbin/ldconfig /sbin/
apt-get install --reinstall libc-bin
apt-get -f install 
apt-get install lib32z1-dev

# 报错dpkg: warning: 'ldconfig' not found in PATH or not executable 编译openssl 
git clone git://git.openssl.org/openssl.git
cd openssl
./config --shared
make
make install

# 编译openssh报错 configure: error: OpenSSL version header not found
ln -s /usr/local/lib/libssl.so.3 /usr/lib/libssl.so.3
ln -s /usr/local/lib/libcrypto.so.3 /usr/lib/libcrypto.so.3

# 编译openssh报错 configure: error: PAM headers not found
apt-get install libpam0g-dev

# 编译openssh报错 configure: error: SELinux support requires selinux.h header

# ssh服务消失
apt-get update
apt-get install ssh
# 选择默认即可
# 最后再重新执行
make install

# 重启服务
systemctl daemon-reload
systemctl restart sshd

# 现在版本
ssh -V
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值