Debian 环境下进行远程登录的常用方式

一、SSH 命令行远程登录(推荐)
sudo apt update && sudo apt install openssh-serversudo systemctl start ssh && sudo systemctl enable sshsudo systemctl status sshssh 用户名@服务器IP(默认端口 22)ssh -p 端口 用户名@服务器IPPermitRootLogin noPasswordAuthentication no,PubkeyAuthentication yesPort 2222(示例)sudo systemctl restart sshsudo ufw allow ssh(或 sudo ufw allow 2222/tcp)sudo firewall-cmd --add-service=ssh --permanent && sudo firewall-cmd --reloadssh [email protected]ssh [email protected]以上步骤覆盖安装、启动、连接、加固与防火墙放行,适用于 Debian 11/12 等常见版本。二、图形桌面远程访问
sudo apt install xrdp xfce4,sudo systemctl start xrdp && sudo systemctl enable xrdp/etc/xrdp/startwm.sh 中确保调用桌面会话(如加入 exec startxfce4)sudo apt install tigervnc-standalone-server,vncserver 设置访问密码vncserver :1 -geometry 1280x800 -depth 24/etc/systemd/system/vncserver@:1.service):[Unit]Description=Remote desktop service (VNC)After=syslog.target network.target[Service]Type=forkingUser=debianWorkingDirectory=/home/debianPIDFile=/home/debian/.vnc/%H%i.pidExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%iExecStop=/usr/bin/vncserver -kill :%i[Install]WantedBy=multi-user.target启用:sudo systemctl daemon-reload && sudo systemctl enable --now vncserver@:1.servicessh -L 5901:localhost:5901 用户名@服务器IP,然后客户端连接 localhost:5901,可避免直接暴露 VNC 端口。三、连接排障与最佳实践
sudo systemctl status ssh(或 xrdp/vncserver)ss -tlnp | grep -E '(:22|:3389|:5901)'sudo adduser newusersudo journalctl -u ssh -fsudo tail -f /var/log/xrdp.log /var/log/xrdp-sesman.log