OpenSSH 升级加固实例
(一) 升级条件准备
² 关闭防火墙
# service iptables stop
² 安装与启用telnet
开启telnet server,以防止升级OpenSSH时导致远程连接异常,具体Telnet服务安装与开启命令操作如下。
# yum安装telnet-server 服务
# yum install –y telnet-server
# 修改xinted服务配置,启用telnet服务
# vim /etc/xinetd.d/telnet
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no # 此处yes改成no,否则默认telnet服务为关闭状态
}
# service xinetd restart
² 下载相关升级包
# wget https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz --no-check-certificate
# wget http://www.zlib.net/zlib-1.2.11.tar.gz
# wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
² 安装zlib依赖库
# tar zxvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure
# make && make install
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig
² 添加普通账户
# useradd iflytek
# passwd iflytek
(二) OpenSSL 升级
# tar zxvf openssl-1.0.2k.tar.gz
# cd openssl-1.0.2k
# ./config shared -fPIC
# make && make install
# echo "/usr/local/ssl/lib " >> /etc/ld.so.conf
# ldconfig
# rm -rf /usr/bin/openssl
# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
# openssl version
(三) OpenSSH 升级
使用命令“telnet IP”远程连接服务器,关闭SSH服务以便升级。
# 停止sshd服务
# service sshd stop
# yum安装pam-devel
# yum install -y pam-devel # 缺少pam-devel会报错
# 删除原ssh中的相关配置文件
# rm -rf /etc/init.d/sshd /etc/ssh /usr/bin/scp /usr/bin/sftp /usr/bin/ssh* /usr/sbin/sshd
# 解压新版openssh并编译安装
# tar zxvf openssh-7.4p1.tar.gz
# cd openssh-7.4p1
./configure --prefix=/usr/local/ssh --sysconfdir=/etc/ssh --with-md5-passwords --without-pam --with-ssl-dir=/usr/local/ssl --mandir=/usr/share/man --with-zlib=/usr/local/zlib --with-privsep-path=/var/empty --with-privsep-user=sshd --with-ssl-engine
# make && make install
# 创建新版ssh服务的相关软链接
# ln -s /usr/local/ssh/bin/ssh /usr/bin/ssh
# ln -s /usr/local/ssh/bin/scp /usr/bin/scp
# ln -s /usr/local/ssh/bin/sftp /usr/bin/sftp
# ln -s /usr/local/ssh/bin/ssh-add /usr/bin/ssh-add
# ln -s /usr/local/ssh/bin/ssh-agent /usr/bin/ssh-agent
# ln -s /usr/local/ssh/bin/ssh-keygen /usr/bin/ssh-keygen
# ln -s /usr/local/ssh/bin/ssh-keyscan /usr/bin/ssh-keyscan
# ln -s /usr/local/ssh/sbin/sshd /usr/sbin/sshd
# touch /etc/ssh/ssh_host_key.pub
# 配置ssh启动脚本和自启动项
# cp contrib/redhat/sshd.init /etc/init.d/sshd
# chmod u+x /etc/init.d/sshd
# chkconfig --add sshd
# chkconfig sshd on
#配置允许root远程使用ssh登录(建议使用普通账号作为远程运维登录使用,不要开启root远程登录)
# vi /etc/ssh/sshd_config
去除“#PermitRootLogin prohibit-password”中注释,并修改“prohibit-password”为“yes”,最后保存退出;
# 重新启动新版sshd服务
# /etc/init.d/sshd start
# service sshd status
# 版本校验
# ssh -V
最后新打开一个窗口, 看到以下俩信息就算成功了