本文以 centos 7 操作系统为例
开启telnet服务和FTP服务
检查xinetd,telnet-server,vsftpd
1 2 3 4 5 6 7 8
| rpm -qa | grep xinetd yum install -y xinetd
rpm -qa | grep telnet-server yum install -y telnet-server
rpm -qa | grep vsftpd yum install -y vsftpd
|
配置telnet
1 2 3 4 5 6 7 8 9 10 11 12
| 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 }
|
启动服务
当完成ssh升级之后,一定要把/etc/securetty文件给还原成原来的备份
1 2 3 4
| chkconfig xinetd on mv /etc/securetty /etc/securetty.old service xinetd start service vsftpd start
|
使用 telnet 登录
1 2 3 4
| telnet SERVER_IP 23
login: root password: xxxxx
|
openssl 升级(默认)
依赖
1
| sudo yum -y install perl perl-devel gcc gcc-c++
|
升级当前版本
1 2 3 4
| cd /usr/local/src wget https:// xxxx tar zxvf openssl_xxx.gz cd openssl_x_x
|
编译安装
1 2 3 4
| ./config make make test make install
|
替换旧版本
1 2
| sudo mv /usr/bin/openssl /usr/bin/oldopenssl sudo ln -s /usr/local/bin/openssl /usr/bin/openssl
|
如果查看 openssl-version 报错误
1 2
| sudo ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/ sudo ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/
|
openssl 升级(自定义)
下载 openssl 源码包
1 2 3 4 5
| yum -y install gcc perl
cd /usr/local/src wget https://mirrors.cloud.tencent.com/openssl/source/openssl-1.1.1i.tar.gz
|
卸载旧版
1 2 3 4 5
| rpm -qa | grep openssl
rpm -e openssl --nodeps
|
编译安装
1 2 3 4 5 6 7 8
| cd /usr/local/src tar -zxvf openssl-1.1.1i.tar.gz
./config --prefix=/usr --shared
make make test make install
|
查看版本
1 2 3 4 5
| openssl version
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
|
openssh 升级
备份当前配置
1 2
| mv /etc/ssh /etc/ssh.old mv /etc/init.d/sshd /etc/init.d/sshd.old
|
安装依赖
1 2 3
| yum install wget gcc -y yum install -y zlib-devel openssl-devel yum install pam-devel libselinux-devel zlib-devel openssl-devel -y
|
下载软件包
1 2
| cd /usr/local/src wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz
|
删除低版本
1
| rpm -e --nodeps `rpm -qa | grep openssh`
|
安装 openssh
1 2 3
| cd /usr/local/src tar -zxvf openssh-8.4p1.tar.gz cd openssh-8.4p1
|
配置安装
1
| ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr --without-hardening
|
赋权
1
| chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
|
复制配置文件并且设置允许root用户远程登录
1 2 3 4 5 6
| cd /usr/local/src/openssl-x.x.x
cp -a contrib/redhat/sshd.init /etc/init.d/sshd cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam chmod u+x /etc/init.d/sshd vim /etc/ssh/sshd_config
|
vim 文件中这样配置
1 2 3 4 5 6
| PermitRootLogin yes
...
PasswordAuthentication yes
|
添加ssh到开机启动
1 2
| chkconfig --add sshd chkconfig sshd on
|
重启服务
1 2 3
| systemctl restart sshd
ssh -V
|
关闭 telnet
1 2 3
| mv /etc/securetty.old /etc/securetty chkconfig xinetd off service xinetd stop
|
如果需要之前ssh配置信息
1 2
| rm -rf /etc/ssh mv /etc/ssh.old /etc/ssh
|
Ubuntu系统
对于Ubuntu系统,比centos要简单不少
下载最新版本
1 2 3
| cd /usr/local/src sudo wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz sudo tar -zxvf openssl-1.1.1i.tar.gz
|
编译安装
1 2 3 4 5 6
|
cd openssl-1.1.1i sudo ./config sudo make sudo make install
|
删除旧版本
1
| sudo rm /usr/bin/openssl
|
为新版本 openssl 建立软链接
1
| sudo ln -s /usr/local/bin/openssl /usr/bin/openssl
|
查看版本
1 2 3 4 5 6
| openssl version
cd /usr/local/src/openssl-1.1i sudo cp libssl.so.1.1 /lib/x86_64-linux-gnu sudo cp libcrypto.so.1.1 /lib/x86_64-linux-gnu
|
centos8 升级方法
通过yum更新
安装依赖
1 2
| yum -y install wget tar gcc make sudo yum -y install perl perl-devel gcc gcc-c++
|
上传依赖包
1 2 3 4 5
| 上传 zlib-1.2.11.tar.gz,openssl-1.1.1d .tar.gz,openssh-8.2p1.tar.gz
tar --no-same-owner -zxf zlib-1.2.11.tar.gz tar --no-same-owner -zxf openssl-1.1.1d_.tar.gz tar --no-same-owner -zxf openssh-8.2p1.tar.gz
|
安装zlib
1 2 3
| cd zlib-1.2.11 ./configure --prefix=/usr/local/zlib make && make install
|
安装openssl
1 2 3 4 5
| cd openssl-1.1.1d ./config --prefix=/usr/local/ssl -d shared make && make install echo '/usr/local/ssl/lib' >> /etc/ld.so.conf ldconfig -v
|
安装openssh
1 2 3
| cd openssh-8.2p1 ./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl make && make install
|
卸载由yum安装的openssh
修改配置
1 2 3 4 5 6
| vim /usr/local/openssh/etc/sshd_config
PermitRootLogin yes PubkeyAuthentication yes PasswordAuthentication yes
|
复制到相应文件夹
1 2 3
| cp /mnt/update/openssh-8.2p1/contrib/redhat/sshd.init /etc/init.d/sshd
|
1 2 3 4 5 6
| chkconfig --add sshd cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd cp /usr/local/openssh/bin/ssh /usr/bin/ssh cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
|
启动
其他相关命令
重启命令
1 2
| systemctl start sshd.service systemctl restart sshd.service
|
查看状态
1
| systemctl status sshd.service
|
启动服务
1
| systemctl start sshd.service
|
开机自动启动
1
| systemctl enable sshd.service
|
查看消息