VPS 改 SSH 端口,使用密钥登录——提高 VPS 安全基础操作。使用 SSHKey_Installer 一键安装 VPS 密钥,懒人必备。
项目地址:KiritoMiao - SSHKEY_Installer
使用方法:
1、登录 GitHub,绑定公钥:
https://github.com/settings/keys
2、SSH root 登录 VPS,执行命令:
wget https://github.com/KiritoMiao/SSHKEY_Installer/raw/master/key.sh --no-check-certificate && bash key.sh [你的 Github 用户名]
完成后,就可以使用密钥登录 VPS,同时会关闭密码登录。
手工配置公钥登录方法参考:https://cyhour.com/550/
修改 SSH 端口方法:https://cyhour.com/611/
附上 SSHKey_Installer 源代码:
#/bin/sh
apt-get update -y
apt-get install curl -y
yum clean all
yum make cache
yum install curl -y
echo '============================
SSH Key Installer
V1.0 Alpha
Author:Kirito
============================'
cd ~
mkdir .ssh
cd .ssh
curl https://github.com/$1.keys > authorized_keys
chmod 700 authorized_keys
cd ../
chmod 600 .ssh
cd /etc/ssh/
sed -i "/PasswordAuthentication no/c PasswordAuthentication no" sshd_config
sed -i "/RSAAuthentication no/c RSAAuthentication yes" sshd_config
sed -i "/PubkeyAuthentication no/c PubkeyAuthentication yes" sshd_config
sed -i "/PasswordAuthentication yes/c PasswordAuthentication no" sshd_config
sed -i "/RSAAuthentication yes/c RSAAuthentication yes" sshd_config
sed -i "/PubkeyAuthentication yes/c PubkeyAuthentication yes" sshd_config
service sshd restart
service ssh restart
systemctl restart sshd
systemctl restart ssh
cd ~
rm -rf key.sh
Comments:0