從一個(gè)全新的centos7虛擬機(jī)到手,走一個(gè)升級(jí)openssh&openssl的流程
更新一下:
yum update
安裝gcc編譯器:
yum install gcc
安裝zlib依賴庫(kù):
yum install zlib-devel
安裝openssl依賴庫(kù)
yum install openssl-devel
ifconfig,如果輸入“bash: ifconfig: 未找到命令”**
yum install -y net-tools.x86_64
Operating system: x86_64-whatever-linux2 You need Perl 5.
下載perl5鏈接:
https://www.cpan.org/src/5.0/perl-5.30.1.tar.gz
解壓:
tar -xzf perl-5.30.1.tar.gz
預(yù)編譯:
./Configure -des -Dprefix=$HOME/localperl
編譯:
make
測(cè)試:
make test
安裝:
make install
安裝openssl
下載:
https://www.openssl.org/source/openssl-1.1.1c.tar.gz
解壓:
tar -zxvf openssl-1.1.1c.tar.gz
預(yù)編譯&配置:
./config --prefix=/usr/local/openssl? ? \#如果報(bào)錯(cuò)击碗,按照需要安裝perl以及gcc包
編譯&安裝:
make && make install
備份:
mv /usr/bin/openssl /usr/bin/openssl.bak
建立軟鏈接:
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
更新動(dòng)態(tài)鏈接庫(kù)數(shù)據(jù):
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
設(shè)置生效:
ldconfig
查看版本:
openssl version
安裝openssh8.2
下載:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
解壓:tar –zxvf openssh-8.2p1.tar.gz
修改源碼:解壓主目錄下届吁,找到sshd.c文件育苟,vim sshd.c
找到:
server_accept_loop(&sock_in,&sock_out,
&newsock,config_s);c
修改為:
sd_notify(0, "READY=1");
server_accept_loop(&sock_in, &sock_out,
? ? ? ?? &newsock, config_s);
并加上引用頭文件:
#include <systemd/sd-daemon.h>
預(yù)編譯:
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl? --with-zlib? --with-md5-passwords? --with-pam
修改Makefile文件:
原來是:
LIBS=-lcrypto -ldl -lutil -lz? -lcrypt -lresolv
修改后:
LIBS=-lcrypto -ldl -lutil -lz? -lcrypt -lresolv -lsystemd
configure: error: *** zlib.h missing - please install first or check config.log
yum -y install zlib-devel
configure: error: *** working libcrypto not found, check config.log
yum install -y openssl-devel
configure: error: PAM headers not found
yum-yinstallpam-devel
編譯:make
sshd.c:44:31: 致命錯(cuò)誤:systemd/sd-daemon.h:沒有那個(gè)文件或目錄
yum install systemd-devel
安裝:
make install
檢查:
sshd -t
/etc/ssh/sshd_config line 79: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 80: Unsupported option GSSAPICleanupCredentials
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ ? ? ? ? WARNING: UNPROTECTED PRIVATE KEY FILE! ? ? ? ?? @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 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 0640 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 0640 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.
修改權(quán)限:
cd /etc/ssh/
?
chmod 600 ssh_host_ecdsa_key
?
chmod 600 ssh_host_rsa_key
?
chmod 600 ssh_host_ed25519_key
檢查版本:
ssh -V
修改端口:
vim /etc/ssh/sshd_config
Port 2222 #修改端口為2222
PermitRootLogin yes? ? #允許root遠(yuǎn)程登錄
#GSSAPIAuthentication yes? #只管禁掉
#GSSAPICleanupCredentials no? ? #只管禁掉
重啟服務(wù):
service sshd restart
報(bào)錯(cuò):
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
查看日志:
journalctl -xe
報(bào)錯(cuò)日志:
5月 20 16:36:58 localhost.localdomain sshd[129668]: error: Bind to port 2222 on 0.0.0.0 failed: Permission denied.
5月 20 16:36:58 localhost.localdomain sshd[129668]: fatal: Cannot bind any address.
5月 20 16:36:58 localhost.localdomain systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
5月 20 16:36:58 localhost.localdomain systemd[1]: Failed to start OpenSSH server daemon.
關(guān)閉selinux:
setenforce 0
重啟服務(wù):
service sshd restart
永久關(guān)閉selinx:
vim /etc/sysconfig/selinux
將SELINUX=enforcing改為SELINUX=disabled
重啟后生效
對(duì)了慢逾,千萬不要在正式環(huán)境這么操作歧强,因?yàn)檫@樣很危險(xiǎn)反番。
正確的步驟是先把服務(wù)器telnet打開沙热,再遠(yuǎn)程連上telnet,使用telnet操作這一切罢缸,不然要是升級(jí)過程中出了問題篙贸,只能跑到機(jī)房去搞了。
于是便有了下面的telnet踩坑:
檢查是不是安裝了telnet:
rpm -qa | grep telnet? # 安裝了telnet和telnet-server
rpm -qa xinetd? ? #是否安裝了xinetd枫疆,telnet的自啟動(dòng)依賴它
安裝:
yum install telnet-server
yum install telnet
yum install -y xinetd
啟動(dòng):
systemctl start telnet.socket? #啟動(dòng)telent服務(wù)
systemctl start xinetd.service? #啟動(dòng)守護(hù)進(jìn)程
遠(yuǎn)程連接telnet歉秫,輸入正確賬戶密碼報(bào)錯(cuò):
Login incorrect
執(zhí)行:
mv /etc/securetty /etc/securettyold
再次遠(yuǎn)程登錄,成功养铸。
最后插一句:一般來說雁芙,服務(wù)器的防火墻和selinux是不開的。因?yàn)橛龅胶芏鄦栴}钞螟,找不到答案兔甘,最后發(fā)現(xiàn)是這兩東西搗的鬼,真是氣人鳞滨。