此处升级操做的原则是保留系统原有ssh服务,新安装高版本ssh服务html
一、下载openssh源码包服务器
http://www.openssh.com/portable.htmlsession
二、安装
#tar zxvf openssh-7.2p2.tar.gz
#cd openssh-7.2p2
#./configure --prefix=/usr/local/openssh --sysconfdir=/usr/local/openssh/etc --with-pam --with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib
#make && make install
三、配置启动脚本和配置文件
cp /etc/init.d/sshd /ghca/bak/sshd #备份旧版sshd启动脚本
cp /ghca/openssh-7.2p2/contrib/redhat/sshd.init /etc/init.d/sshd ##拷贝新版启动脚本
vi /etc/init.d/sshd #编辑启动脚本less
主要将如下内容ssh
SSHD=/usr/sbin/sshd /usr/bin/ssh-keygen -A /sbin/restorecon /etc/ssh/ssh_host_key.pub /sbin/restorecon /etc/ssh/ssh_host_rsa_key.pub /sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub /sbin/restorecon /etc/ssh/ssh_host_ecdsa_key.pub
修改成:spa
SSHD=/usr/local/openssh/sbin/sshd /usr/local/openssh/bin/ssh-keygen -A /sbin/restorecon /usr/local/openssh/etc/ssh_host_key.pub /sbin/restorecon /usr/local/openssh/etc/ssh_host_rsa_key.pub /sbin/restorecon /usr/local/openssh/etc/ssh_host_dsa_key.pub /sbin/restorecon /usr/local/openssh/etc/ssh_host_ecdsa_key.pub
注意:此时/usr/local/openssh/etc目录下可能没有那几个key,可是也能够先这样修改,具体这个几个key的用法还没作研究。rest
四、配置公私钥文件
#cd /root/.ssh
#/usr/local/openssh/bin/ssh-keygen -t rsa #生成公私钥对
#cat id_rsa.pub >> authorized_keys #写入公钥到服务器认证文件
五、将私钥文件下载保存至本地
/root/.ssh/id_rsa
六、重启sshd服务
/etc/init.d/sshd restart
七、配置本地SecureCRT并登陆服务器
将对应服务器登陆session配置中去掉密码验证,并配置公钥路径,以下图:code
注意:openssh7.0之后就不容许root使用交互模式密码登陆了,必须使用公钥登陆,普通帐号可使用密码方式登陆。htm
* The default for the sshd_config(5) PermitRootLogin option has
changed from "yes" to "prohibit-password".
* PermitRootLogin=without-password/prohibit-password now bans all
interactive authentication methods, allowing only public-key,
hostbased and GSSAPI authentication (previously it permitted
keyboard-interactive and password-less authentication if those
were enabled).
详见:http://bluereader.org/article/66465824?qqdrsign=07af0blog