1. 安装 SSH 服务
sudo apt update
sudo apt install openssh-server
  1. 设置开启自启
# 启动
sudo systemctl start ssh
# 开机自启
sudo systemctl enable ssh
# 检查当前是否在运行
sudo systemctl status ssh
  1. 修改ssh配置项
sudo vim /etc/ssh/sshd_config

# 找到并取消注释
PermitRootLogin yes            # 允许root登录
PasswordAuthentication yes

# 重启服务
sudo systemctl restart ssh
  1. 防火墙允许SSH
sudo ufw allow ssh

# 重启服务
sudo systemctl restart ssh
  1. 测试 SSH 链接
ssh root@ipxx.xx.xx -p 22