一 安装telnet服务器
安装telnet服务器目的,防止我们升级失败的时候,可以通过telnet登录,而不至于上机房。
由于我们是临时启动,所以只要简单的使用,不要通过xinetd来进行守护。
命令如下:
yum -y install telnet telnet-server
systemctl enable telnet.socket --now
systemctl start telnet.socket
#防火墙设置
firewall-cmd --list-port
firewall-cmd --permanent --add-port=23/tcp
firewall-cmd –reload
注意,默认是不能通过root登录的、root登录比较麻烦。
二 编译centos7下的openssh
2.1 安装必要依赖包
yum install rpm-build zlib-devel openssl-devel gcc perl-devel pam-devel unzip libXt-devel imake gtk2-devel -y
2.2 编译打包rpm文件
建立文件:
mkdir -p /root/rpmbuild/SPECS
mkdir -p /root/rpmbuild/SOURCES
上传到文件
openssh-9.6p1.tar.gz
和openssh-9.6p1.tar.gz
下载地址:
https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz
解压打包:
tar -zxf openssh-9.3p1.tar.gz
cp openssh-9.6p1/contrib/redhat/openssh.spec ./
#关掉no_gnome_askpass no_x11_askpass这两个参数
sed -i -e "s/%define no_x11_askpass 0/%define no_x11_askpass 1/g" openssh.spec
sed -i -e "s/%define no_gnome_askpass 0/%define no_gnome_askpass 1/g" openssh.spec
#rpm 制作
rpmbuild -ba openssh.spec
报错:
extracting debug info from /root/rpmbuild/BUILDROOT/openssh-9.6p1-1.el7.centos.x86_64/usr/libexec/openssh/x11-ssh-askpass
*** ERROR: No build ID note found in /root/rpmbuild/BUILDROOT/openssh-9.6p1-1.el7.centos.x86_64/usr/libexec/openssh/x11-ssh-askpass
error: Bad exit status from /var/tmp/rpm-tmp.9Mxy8c (%install)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.9Mxy8c (%install)
在spec文件任意位置添加:
%define __debug_install_post \
%{_rpmconfigdir}/find-debuginfo.sh %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
%{nil}
最后制作成功:
...
...
Wrote: /root/rpmbuild/SRPMS/openssh-9.6p1-1.el7.centos.src.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/openssh-9.6p1-1.el7.centos.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/openssh-clients-9.6p1-1.el7.centos.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/openssh-server-9.6p1-1.el7.centos.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/openssh-askpass-9.6p1-1.el7.centos.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/openssh-askpass-gnome-9.6p1-1.el7.centos.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/openssh-debuginfo-9.6p1-1.el7.centos.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.FgdHrz
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd openssh-9.6p1
+ rm -rf /root/rpmbuild/BUILDROOT/openssh-9.6p1-1.el7.centos.x86_64
+ exit 0
2.3 删除老的rpm
yum remove openssh-server-7.4p1-11.el7.x86_64
yum remove openssh-7.4p1-11.el7.x86_64
安装新的sshd
[root@localhost x86_64]# cd /root/rpmbuild/RPMS/x86_64
[root@localhost x86_64]# rpm -ivh *.rpm
Preparing... ################################# [100%]
Updating / installing...
1:openssh-9.6p1-1.el7.centos ################################# [ 17%]
2:openssh-askpass-9.6p1-1.el7.cento################################# [ 33%]
3:openssh-askpass-gnome-9.6p1-1.el7################################# [ 50%]
4:openssh-clients-9.6p1-1.el7.cento################################# [ 67%]
5:openssh-server-9.6p1-1.el7.centos################################# [ 83%]
6:openssh-debuginfo-9.6p1-1.el7.cen################################# [100%]
重启:
systemctl restart sshd
报错:
Mar 03 16:38:33 localhost.localdomain sshd[20551]: Starting sshd:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 03 16:38:33 localhost.localdomain sshd[20551]: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
Mar 03 16:38:33 localhost.localdomain sshd[20551]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 03 16:38:33 localhost.localdomain sshd[20551]: Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: It is required that your private key files are NOT accessible by others.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: This private key will be ignored.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 03 16:38:33 localhost.localdomain sshd[20551]: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
Mar 03 16:38:33 localhost.localdomain sshd[20551]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mar 03 16:38:33 localhost.localdomain sshd[20551]: Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: It is required that your private key files are NOT accessible by others.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: This private key will be ignored.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: sshd: no hostkeys available -- exiting.
Mar 03 16:38:33 localhost.localdomain sshd[20551]: [FAILED]
Mar 03 16:38:33 localhost.localdomain systemd[1]: sshd.service: control process exited, code=exited status=1
Mar 03 16:38:33 localhost.localdomain systemd[1]: Failed to start SYSV: OpenSSH server daemon.
-- Subject: Unit sshd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sshd.service has failed.
--
-- The result is failed.
Mar 03 16:38:33 localhost.localdomain systemd[1]: Unit sshd.service entered failed state.
Mar 03 16:38:33 localhost.localdomain systemd[1]: sshd.service failed.
Mar 03 16:38:33 localhost.localdomain polkitd[549]: Unregistered Authentication Agent for unix-process:20545:886109 (system bus name :1.91, object path /org/freedesktop/PolicyKit1/AuthenticationAgent,
更改:
[root@localhost ~]# chmod 0600 /etc/ssh/ssh_host_rsa_key
[root@localhost ~]# chmod 0600 /etc/ssh/ssh_host_ecdsa_key
[root@localhost ~]# chmod 0600 /etc/ssh/ssh_host_ed25519_key
[root@localhost ~]# sshd -t
2.4 设置root登录
更改准许root登录:
vim /etc/ssh/sshd_config
#搜索PermitRootLogin 设置成yes
PermitRootLogin yes
重启服务:
systemctl restart sshd