升级SSH版本

查看版本

查看ssh版本

ssh -V

查看系统版本

lsb_release -a

安装telnet

注:另一个远程登录工具,ssh升级失败仍能登录服务器

安装相关工具

yum install telnet telnet-server xinetd -y

添加telnet配置

vi /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
#       unencrypted username/password pairs for authentication.
service telnet
{
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/sbin/in.telnetd
        log_on_failure  += USERID
        disable         = yes
}

# socket_type : stream->tcp,datagrum=>udp
# wait : no 同时允许两个人登录,yes为只同时允许一个人,要等待
# disable : 不允许root登录

新建连接用户(推荐)

useradd teluser
passwd teluser

允许root登录(不推荐)

增加虚拟控制台

vi /etc/securetty
#增加
pts/0
pts/1
pts/2

允许root登录

Edit /etc/pam.d/login and /etc/pam.d/remote

注释以下语句

auth required pam_securetty.so 

启动服务

# 启动telnet
systemctl start telnet.socket

# 自启telnet
systemctl enable telnet.socket

# 启动xinetd
service xinetd start

# 自启xinetd
systemctl enable xinetd.service

# 其他相关
# 查看列表
systemctl list-unit-files

开放23端口

注: 如果未安装iptables则跳过

显示现有规则表

iptables -L -n --line-numbers

添加23端口

vi /etc/sysconfig/iptables  

添加下述规则

-A INPUT -p tcp -m state --state NEW --dport 23 -j ACCEPT

重启

service iptables restart

测试

  • 测试是否连接成功
  • 重启电脑查看是否连接成功

软件说明

telnet-server telnet

非独立守护进程,绑定在xinetd守护服务程序,默认明文传输

xinetd

超级守护进程,可以代理那些不常用的非独立守护进程监听在相应的端口

升级openssh

安装必要的软件

yum -y install gcc pam pam-devel zlib zlib-devel

zlib

zlib是提供数据压缩用的函式库

pam

PAM机制是一个非常成熟的安全认证机制,可以为Linux多种应用提供安全,可靠的认证服务

安装openssh

备份,/etc/ssh必须删除原有配置,否在在make install时不能覆盖配置

mv /etc/ssh /etc/ssh_bak
mv /etc/pam.d/sshd /etc/pam.d/sshd_bak
mv /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.service_bak

卸载旧版本

# -e 删除包
# --nodeps 不删除依赖
# -qa 查询所有安装的包
rpm -e --nodeps `rpm -qa | grep openssh`

下载解压

# 下载源码
wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz 

# 解压
tar xzf openssh-7.5p1.tar.gz

安装

./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords
make
make install

服务配置

系统服务

cp contrib/redhat/sshd.init /etc/init.d/sshd

pam配置

mv /etc/pam.d/sshd_bak /etc/pam.d/sshd

如果未备份则新建文件

vi /etc/pam.d/sshd
#%PAM-1.0
auth       required pam_sepermit.so
auth       substack     password-auth
auth       include      postlogin
# Used with polkit to reauthorize users in remote sessions
-auth      optional     pam_reauthorize.so prepare
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      password-auth
session    include      postlogin
# Used with polkit to reauthorize users in remote sessions
-session   optional     pam_reauthorize.so prepare

开机自启

chkconfig --add sshd

修改配置

sshd_config

vi /etc/ssh/sshd_config

# 允许root登录
PermitRootLogin yes

# 使用pam
UsePAM yes

测试命令

/usr/sbin/sshd -t -f /etc/ssh/sshd_config

重启服务

service sshd restart

测试

  • 重启服务器测试ssh是否成功

删除telnet相关软件

yum remove telnet telnet-server xinetd -y
升级SSH版本通常 involves replacing the existing OpenSSH package with a newer version. This process can vary slightly depending on the Linux distribution you are using. Below are general steps for upgrading SSH on a Linux system, with a focus on CentOS as implied by the reference material. ### 准备工作 Before proceeding with the upgrade, it is crucial to ensure that you have a backup of important data and configurations. Additionally, having a way to access the server outside of SSH (such as through a console) is advisable in case something goes wrong during the upgrade process. ### 升级SSH For systems based on Red Hat, like CentOS, you would typically use the `yum` or `dnf` package manager to update OpenSSH. However, if you require a version that is not available in the default repositories, you may need to compile OpenSSH from source. #### 使用包管理器更新 If the latest version of OpenSSH is available in the repository, you can update it using the following command: ```bash sudo yum update openssh-server ``` Or for `dnf`: ```bash sudo dnf upgrade openssh-server ``` #### 从源码编译安装 If the desired version is not available in the repository, you can download the latest stable release from the official OpenSSH website, compile, and install it manually. ```bash wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz tar -zxvf openssh-8.4p1.tar.gz cd openssh-8.4p1 ./configure make sudo make install ``` After installation, verify the installation by checking the version: ```bash ssh -V ``` ### 验证升级 Once the upgrade is complete, it's essential to verify that the new version of SSH is running correctly. You can do this by connecting to the server via SSH from another terminal or machine. ```bash ssh username@your_server_ip ``` Also, check the running version of SSH to confirm the upgrade: ```bash ssh -V ``` It's also a good idea to review the configuration file `/etc/ssh/sshd_config` to ensure no changes are needed for the new version and restart the SSH service to apply any potential configuration changes. ```bash sudo systemctl restart sshd ``` ### 安全性考虑 Upgrading SSH should also involve reviewing the security settings. For instance, if you're using an older version of CentOS that ships with an outdated version of OpenSSH, upgrading to a newer version can help mitigate known vulnerabilities [^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值