CentOS7.X OpenSSH OpenSSL 加固指南
本次撰写背景
- 因操作系统过于老旧,部分用户使用的中间件可能依赖于过老的 OpenSSL组件,如果刻意升级较新OpenSSL可能会影响现有应用的正常运行
本次撰写的目的
- 使新版本的OpenSSL 与系统现有版本共存
- 只限升级后的OpenSSH使用升级过的OpenSSL 其他模块链接情况不受影响
升级步骤
编辑 CentOS-Base.repo,将无效的软件源链接清除

yum clean all
yum makecache
-
加固前所需下载安装的软件包:
zlib; zlib-devel;gcc; make; pam-devel;perl;openssl-devel;perl-CPAN
当编译OpenSSL报错 “Can‘t locate IPC/Cmd.pm” 时 请使用以下方法
yum install -y perl-CPAN
#进入CPAN的shell模式
perl -MCPAN -e shell
# 首次进入需要配置shell,按照提示操作即可,我这里是一路回车。
# 在shell中安装缺少的模块
install IPC/Cmd.pm
# 安装完成后输入exit 退出
解压openssl tar.gz 包之后,到OpenSSL 目录下
./config --prefix=/usr/local/openssl3_for_ssh --openssldir=/etc/ssl --shared zlib
make
make install
# openssl3 为链接库目录 建议自定义,但不建议放到 /usr 或 /usr/bin 下 这类目录由发行版控制.
# 可以放到 /usr/local 下 切记不要替换或覆盖原旧版本OpenSSL链接库
echo "/usr/local/openssl3_for_ssh/lib64" >> /etc/ld.so.conf //添加库路径关联 这一步和编译OpenSSH 相关
ldconfig
解压 openssh.tar.gz 包之后 到 OpenSSH目录下
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-zlib --with-ssl-dir=/usr/local/openssl3_for_ssh \
--with-md5-passwords --with-pam --with-selinux --mandir=/usr/share/man
make
make install
echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
chkconfig --list sshd
service sshd restart

-
注意事项:
可以选择 备份 /etc/pam.d
可以选择 将 /etc/ssh/sshd_config 文件作为备份移动到其他目录
-
如果提示:
/etc/ssh/sshd_config line 79: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 80: Unsupported option GSSAPICleanupCredentials
可以选择到 sshd_config 中注释报错选项
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Unable to load host key "/etc/ssh/ssh_host_rsa_key": bad permissions
Unable to load host key: /etc/ssh/ssh_host_rsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Unable to load host key "/etc/ssh/ssh_host_ecdsa_key": bad permissions
Unable to load host key: /etc/ssh/ssh_host_ecdsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Unable to load host key "/etc/ssh/ssh_host_ed25519_key": bad permissions
Unable to load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.
make: [check-config] Error 1 (ignored)
可以执行 chmod 600 /etc/ssh/ssh_host* 重新 make install