远程 SSH 登录 Ubuntu
远程 SSH 登录这台 Ubuntu,直接在 Ubuntu 终端执行下面这一整条命令:
apt update && apt install -y openssh-server && systemctl enable --now ssh && systemctl status ssh --no-pager && hostname -I
确认输出中显示:
Active: active (running)
并记下最后显示的 Ubuntu IP,例如:
192.168.1.100
因为你当前使用的是 root,Ubuntu 默认可能禁止 root 密码登录。建议创建一个专门的 SSH 管理账号:
adduser sshadmin
按照提示设置密码,然后授予 sudo 权限:
usermod -aG sudo sshadmin
在 Windows 上打开 PowerShell,连接:
ssh sshadmin@192.168.1.100
第一次连接输入:
yes
然后输入刚设置的密码。输入密码时屏幕不会显示字符,这是正常现象。
如果连接不上,在 Ubuntu 上执行:
ss -lntp | grep ':22' ufw status
如果 UFW 已启用:
ufw allow 22/tcp
如果你就是想直接用 root 登录,需要额外设置,但安全性较低:
passwd root sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config sshd -t && systemctl restart ssh