ssh配置
生成密钥对
ssh-keygen -t rsa -b 4096
它会提示你选择存储位置,默认是
~/.ssh/id_rsa (私钥)
~/.ssh/id_rsa.pub (公钥)
追加公钥到本地
~/.ssh/authorized_keys
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
首先查看/etc/ssh/sshd_config.d目录下有没有配置文件,有的话使用这个目录下的, 没有的话使用/etc/ssh目录下的sshd_config 禁用密码登录,禁用root账户ssh
PasswordAuthentication no
PermitRootLogin no
开启防火墙
sudo ufw allow 22/tcp # 允许 SSH
sudo ufw enable # 启用防火墙
sudo ufw status # 查看状态
重启ssh服务
sudo systemctl restart ssh