目录
安装所需软件:
也可在官网下载所需版本,其它版本未经测试,使用前请先在测试环境测试。
安装前尽量先开启telnet,以防不测。
也可以在执行完每条编译命令和安装命令后执行echo $?,输出0即为正常无报错。
若有问题欢迎留言讨论。
1、卸载openssh
查询系统自带的openssh包
rpm -qa|grep openssh
卸载系统自带的openssh包
rpm -e --nodeps openssh…… (--nodeps为强制卸载,不动用依赖包)
2、安装zlib
解压压缩包
tar -zxvf zlib-1.2.11.tar.gz
进入目录
cd zlib-1.2.11
编译并安装
1. ./configure --prefix=/usr/local/zlib
2. make
3. make install
3、安装openssl
解压压缩包
tar -zxvf openssl-1.1.1m.tar.gz
进入目录
cd openssl-1.1.1m
编译并安装
./config --prefix=/usr/local/openssl
make
make install
4、安装pam-devel
rpm -ivh pam-devel-1.1.1-10.el6_2.1.x86_64.rpm
5、安装openssh
解压压缩包
tar -zxvf openssh-9.8p1.tar.gz
进入目录
cd openssh-9.8p1
将新编译的openssl library 加入系统动态库连接中
vim /etc/ld.so.conf
添加openssl安装目录
/usr/local/openssl/lib
刷新库文件
ldconfig
编译并安装
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-md5-passwords --without-hardening --enable-dsa-keys --with-pam
make
make install
配置dsa密钥:
./ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
两次回车(这是输入两次密码短语,可为空,按需使用)
修复 SELinux 上下文(若是开启selinux则需要执行此命令):
restorecon -Rv /etc/ssh
修改配置文件
cp contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
vim /etc/init.d/sshd
修改下列两行
25行 SSHD=/usr/sbin/sshd 为 SSHD=/usr/local/openssh/sbin/sshd
42行 /usr/bin/ssh-keygen -A 为 /usr/local/openssh/bin/ssh-keygen -A
保存退出
加入到系统服务
chkconfig --add sshd
重启sshd服务
service sshd restart
修改配置文件
vim /etc/ssh/sshd_config
将PermitRootLogin no(有时是PermitRootLogin prohibit-password)改为PermitRootLogin yes
重启sshd服务
service sshd restart
设置 ssh -V验证码版本
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/
查看ssh版本
ssh -V