一、依赖包安装
依赖包下载网址:
https://debian.pkgs.org/sid/debian-main-amd64/
下载好将依赖包放入/software,安装
mkdir /software
cd /software
dpkg -i libsepol1-dev_3.0-1_amd64.deb
dpkg -i libselinux1-dev_3.0-1build2_amd64.deb
dpkg -i libpam0g_1.3.1.11-1+dde_amd64.deb
dpkg -i libpam0g-dev_1.3.1.11-1+dde_amd64.deb
apt install libssl-dev
二、修改ssh配置
备份ssh配置
cp -rf /etc/ssh /etc/ssh.bak
设置文件权限
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key
配置sshd配置
sed -i 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication/#&/' /etc/ssh/sshd_config
sed -i 's/^GSSAPICleanupCredentials/#&/' /etc/ssh/sshd_config
sed -i 's/^UsePAM/#&/' /etc/ssh/sshd_config
配置service, 取消notify
sed -i 's/^Type/#&/' /lib/systemd/system/ssh.service
三、导入包
openssh下载地址:
https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/
将openssh的安装包放到/software下 解压安装
cd /software
tar zxf openssh-8.9p1.tar.gz
cd openssh-8.9p1
./configure --prefix=/usr --with-privsep-path=/var/empty/sshd/ \
--sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl/ \
--with-default-path=/usr/local/bin:/bin:/usr/bin \
--with-superuser-path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin \
--with-pam --with-selinux --disable-strip --with-md5-passwords
make -j 4(电脑有几核就写几,我这边是4核)
make install
重启服务
systemctl daemon-reload
systemctl restart sshd
检测现在版本
ssh -V
telnet 127.0.0.1 22
为了安全,我这边还进行了版本号隐藏
四、隐藏版本号
cp /usr/sbin/sshd /usr/sbin/sshd.bak
strings /usr/sbin/sshd | grep OpenSSH_8.9
展示的结果是这一行
OpenSSH_8.9p1
OpenSSH_8.9
sed -i 's/OpenSSH_8.9/OpenSSH_*.*/g' /usr/sbin/sshd
telnet 127.0.0.1 22(如果显示版本是*.*即表示隐藏成功)
五、修改默认端口号
vim /etc/ssh/sshd_config
修改第14行的22端口改为自己想定义的端口
systemctl restart sshd (重启之后再开一个窗口,用22端口连,发现已经连不上了,然后改100端口)
telnet 127.0.0.1 100(有响应表示成功)
|