在Debian上使用TigerVNC实现远程打印的完整步骤
首先更新系统软件包并安装TigerVNC服务器及相关依赖:
sudo apt update
sudo apt install tigervnc-standalone-server tigervnc-common
安装完成后,通过vncpasswd命令为用户设置VNC访问密码(后续连接时需用到):
vncpasswd
创建或修改用户主目录下的.vnc/xstartup文件(如~/.vnc/xstartup),添加以下内容以启动GNOME桌面环境(根据实际桌面环境调整,如KDE需替换为startkde):
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
gnome-panel &
metacity &
nautilus &
gnome-terminal &
dbus-launch --exit-with-session gnome-session &
保存后赋予文件执行权限:
chmod +x ~/.vnc/xstartup
使用以下命令启动VNC服务器(:1表示显示编号,对应端口5901;-localhost no允许远程连接):
vncserver :1 -localhost no -geometry 1920x1080
启动后会显示会话信息,如“New ‘X’ desktop is :1”,并生成日志文件(位于~/.vnc/:1.log)。
CUPS(Common Unix Printing System)是Linux系统的标准打印框架,需先安装:
sudo apt update
sudo apt install cups
启动CUPS服务并设置为开机自启:
sudo systemctl start cups
sudo systemctl enable cups
编辑CUPS配置文件/etc/cups/cupsd.conf,修改以下内容:
<Location />部分,替换为:<Location />
Order allow,deny
Allow all
</Location>
<Location /admin>部分,替换为:<Location /admin>
Order allow,deny
Allow all
</Location>
保存后重启CUPS服务使配置生效:
sudo systemctl restart cups
通过CUPS Web界面添加打印机:
http://your_server_ip:631(替换为服务器实际IP)。在客户端计算机(如Windows、Linux)上安装TigerVNC Viewer(从官网下载对应版本)。
打开TigerVNC Viewer,输入服务器IP地址和显示编号(如your_server_ip:1),点击“Connect”,输入之前设置的VNC密码登录。
若客户端为Linux系统,需安装CUPS客户端工具以访问服务器打印机:
sudo apt update
sudo apt install cups-client
在客户端系统中添加服务器共享的打印机:
lpadmin)。http://your_server_ip:631/printers/printer_name,printer_name为CUPS中添加的打印机名称)。cupsd.conf默认允许所有IP访问,建议限制为特定网段(如Allow 192.168.1.0/24),并启用HTTPS(修改Listen指令为https://your_server_ip:631)。ufw或firewalld,需允许VNC(默认端口5901)和CUPS(端口631)的流量:sudo ufw allow 5901/tcp
sudo ufw allow 631/tcp
sudo ufw reload
/etc/cups/cupsd.conf)中的<Location />允许客户端IP访问,避免权限拒绝错误。~/.vnc/xstartup中的桌面环境启动命令需与服务器实际安装的桌面环境一致(如XFCE需替换为xfce4-session)。