ubuntu open shh9.9安装
步骤一:安装依赖包
sudo apt update
sudo apt install build-essential zlib1g-dev libssl-dev libpam0g-dev libselinux1-dev -y
因无网络需要手动下载依赖包
查看所有包是否已经安装
# 一键检查所有开发包状态
dpkg -l build-essential zlib1g-dev libssl-dev libpam0g-dev libselinux1-dev | grep "^ii"完整安装的情况(显示 5 行结果):
bash
ii build-essential 12.8ubuntu1.1 amd64 Informational list of build-essential packages
ii libpam0g-dev 1.3.1-5ubuntu4.6 amd64 PAM 开发文件
ii libselinux1-dev 3.0-1build2 amd64 SELinux 运行时开发文件
ii libssl-dev 1.1.1f-1ubuntu2.20 amd64 OpenSSL 开发文件
ii zlib1g-dev 1:1.2.11.dfsg-2ubuntu1.5 amd64 压缩库开发文件
实际中我需要手动安装 libpam0g-dev 利用大模型生成所需要的依赖列表
# 生成依赖清单
apt-rdepends libpam0g-dev | grep -v "^ " | sort -u > deps.list
cat deps.listlibc6-dev
libpam0g
libpam-runtime
libselinux1-dev
libpam-modules
libaudit1
libc6
...
使用中科大镜像源 (https://mirrors.ustc.edu.cn/ubuntu/
) 下载所需 .deb
文件:
# 创建下载目录
mkdir -p ~/pam_deps && cd ~/pam_deps# 手动下载所有依赖包(中科大镜像源)
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/p/pam/libpam0g-dev_1.3.1-5ubuntu4.7_amd64.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/p/pam/libpam0g_1.3.1-5ubuntu4.7_amd64.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/p/pam/libpam-runtime_1.3.1-5ubuntu4.7_all.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/g/glibc/libc6-dev_2.31-0ubuntu9.14_amd64.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/s/selinux/libselinux1-dev_3.0-1build2_amd64.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/a/audit/libaudit1_2.8.5-2ubuntu6_amd64.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/p/pam/libpam-modules_1.3.1-5ubuntu4.7_amd64.deb
wget https://mirrors.ustc.edu.cn/ubuntu/pool/main/g/glibc/libc6_2.31-0ubuntu9.14_amd64.deb
拷贝到ubuntu系统进行手动安装
sudo dpkg -i *.deb
步骤二:下载并安装最新的依赖包
# 获取最新版本号(例如 9.3p1)
LATEST_SSH_VER="2.9.9p2"
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-2.9.9p2.tar.gz
tar -xzf openssh-${LATEST_SSH_VER}.tar.gz
cd openssh-${LATEST_SSH_VER}# 配置安装到独立目录(避免覆盖系统旧版)
./configure --prefix=/opt/openssh-new \--sysconfdir=/etc/ssh-new \--with-pam \--with-selinux \--with-md5-passwords \--with-ssl-enginemake
sudo make install
步骤三:配置新版 SSH 服务
sudo nano /etc/systemd/system/ssh-new.service写入以下内容:[Unit]
Description=OpenSSH New Version Server
After=network.target[Service]
Type=simple
ExecStart=/opt/openssh-new/sbin/sshd -D -f /etc/ssh-new/sshd_config
ExecReload=/bin/kill -HUP $MAINPID
Restart=always[Install]
WantedBy=multi-user.target
步骤四. 调整端口与防火墙
# 修改新版 SSH 配置
sudo cp /etc/ssh/sshd_config /etc/ssh-new/
sudo nano /etc/ssh-new/sshd_config
关键修改项:
Port 22 # 确保独占 22 端口# 启用密码认证
PasswordAuthentication yes
# 停止旧服务
sudo systemctl stop ssh# 启动并持久化新服务
sudo systemctl daemon-reload
sudo systemctl enable --now ssh-new# 验证服务状态
systemctl status ssh-new
组件 | 旧版(apt 管理) | 新版(手动编译) |
---|---|---|
安装路径 | /usr/bin/ssh | /opt/openssh-new/bin/ssh |
配置文件 | /etc/ssh/sshd_config | /etc/ssh-new/sshd_config |
服务管理 | systemctl stop ssh | systemctl restart ssh-new |
默认端口 | 已释放给新版 | 独占 22 端口 |
回滚方案
# 停止并禁用新版
sudo systemctl disable --now ssh-new# 恢复旧版 SSH 端口
sudo nano /etc/ssh/sshd_config # 确保 Port 22 未被注释
sudo systemctl start ssh