Openssl
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/ 去下载OpenSSL包
1.1安装telnet服务
yum list |grep telnet
yum install telnet-server.x86_64
1.2安装xinetd服务 yum list |grep xinetd yum install xinetd.x86_64 CentOS 6系列版本修改telnet配置文件(CentOS 7 以及以上版本跳过这一步)
vi /etc/xinetd.d/telnet (7以上版本很可能没这个文件)
由于默认centos不允许使用telnet登录,暂时修改为备份文件。 sudo mv /etc/securetty /etc/securetty.bak 运行telnet service xinetd restart
CentOS 7系列版本通过下面四个指令 开启Telnet
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl enable xinetd
systemctl start xinetd
setenforce 0
2.1卸载原Openssh
[root@k8s-node1 software]# rpm -qa |grep openssh
openssh-clients-7.4p1-11.el7.x86_64
openssh-7.4p1-11.el7.x86_64
openssh-server-7.4p1-11.el7.x86_64
[root@k8s-node1 software]# for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps;done
2.2解压openssh安装包 [root@k8s-node1 software]# tar -zxvf openssh-8.1p1.tar.gz [root@k8s-node1 software]# cd openssh-8.1p1
2.3检测环境是否满足
[root@k8s-node1 openssh-8.1p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers
可能出现的问题 解决问题之后重新检测环境 ./configure
1)configure: error: no acceptable C compiler found in $PATH
yum install -y gcc
2)configure: error: *** zlib.h missing - please install first or check config.log ***
yum install -y zlib-devel
3)configure: error: *** working libcrypto not found, check config.log
yum install -y openssl-devel
4)configure: error: PAM headers not found
yum install -y pam-devel
2.4编译安装
[root@k8s-node1 openssh-8.1p1]# mv /etc/ssh /etc/ssh.bak 或者 rm -rf /etc/ssh
[root@k8s-node1 openssh-8.1p1]# make && make install
······
/usr/bin/install -c -m 644 ssh-pkcs11-helper.8.out /usr/share/man/man8/ssh-pkcs11-helper.8
/usr/bin/mkdir -p /etc/ssh
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
[root@k8s-node1 openssh-8.1p1]#
3.配置
3.1拷贝ssh服务文件
[root@k8s-node1 openssh-8.1p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@k8s-node1 openssh-8.1p1]#
3.2允许root用户远程登录
新增33行:
[root@k8s-node1 openssh-8.1p1]# vi /etc/ssh/sshd_config
1 # $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
······ 32 #PermitRootLogin prohibit-password 33 PermitRootLogin yes(根据需求看之前配置文件) 34 #StrictModes yes 另外根据需求在13行禁止注释掉#Port 22或根据telnet 加入端口 Port 6802 2,禁止22端口 首先修改配置文件vi /etc/ssh/sshd_config 找到#Port 22一段,这里是标识默认使用22端口,修改为如下: #Port 22 Port 你服务器的端口 然后保存退出 执行/etc/init.d/sshd restart 这样SSH端口将同时工作与22和6802上。 记得把端口加入防火墙
测试: 找一台别的服务器ssh下此服务器 ssh -P 6822 root@此服务器ip 能连成功那就ok原文链接:记得把端口加入防火墙 测试: 找一台别的服务器ssh下此服务器 ssh -P 2666 root@此服务器ip 能连成功那就ok 现在请使用ssh工具连接6802端口,来测试是否成功。如果连接成功了,则再次编辑sshd_config的设置,将里边的Port22删除,即可。 之所以先设置成两个端口,测试成功后再关闭一个端口,是为了方式在修改conf的过程中,万一出现掉线、断网、误操作等未知情况时候,还能通过另外一个端口连接上去调试以免发生连接不上必须派人去机房,导致问题更加复杂麻烦。
或者第二种方法
yum install
-y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
yum list |grep telnet
yum -y install telnet-server.x86_64
yum list |grep xinetd
yum -y install xinetd.x86_64
systemctl start xinetd
systemctl enable xinetd
systemctl enable telnet.socket
systemctl start telnet.socket
setenforce 0 如出现该异常,可以: 临时关闭:setenforce 0 永久关闭:sed -is#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
tar -zxvf zlib-1.2.11.tar.gz tar -zxvf openssl-1.1.1g.tar.gz tar -zxvf openssh-8.3p1.tar.gz cd zlib-1.2.11 ./configure --prefix=/usr/local/zlib make && make install cd .. cd openssl-1.1.1g ./config --prefix=/usr/local/ssl -d shared make && make install echo '/usr/local/ssl/lib' >> /etc/ld.so.conf ldconfig -v cd openssl.pc cd .. cd openssh-8.3p1 ./configure --prefix=/usr/local/openssh--with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install echo 'PubkeyAuthentication yes'>>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes'>>/usr/local/openssh/etc/sshd_config
cho 'Port 1569'>>/usr/local/openssh/etc/sshd_config
echo 'PermitRootLogin yes'>>/usr/local/openssh/etc/sshd_config
mv /etc/ssh/sshd_config/etc/ssh/sshd_config.bak
cp /usr/local/openssh/etc/sshd_config/etc/ssh/sshd_config
mv /usr/sbin/sshd /usr/sbin/sshd.bak cp /usr/local/openssh/sbin/sshd/usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak cp /usr/local/openssh/bin/ssh /usr/bin/ssh mv /usr/bin/ssh-keygen/usr/bin/ssh-keygen.bak
cp /usr/local/openssh/bin/ssh-keygen/usr/bin/ssh-keygen
mv /etc/ssh/ssh_host_ecdsa_key.pub/etc/ssh/ssh_host_ecdsa_key.pub.bak
sed -i 's/#GSSAPIAuthenticationno/#GSSAPIAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/#GSSAPICleanupCredentialsyes/#GSSAPICleanupCredentials no/g' /etc/ssh/sshd_config
sed -i 's/#UsePAM no/#UsePAM yes/g'/etc/ssh/sshd_config
systemctl restart sshd ssh -V