debian-11-安装配置-vncserver,关联 Bulleyes, ubuntu, linux, samba, smb, nmbd, 网络共享

  • 参考

Debian 11 上安装VNC Server

  1. 安装
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     # Install XFCE 4
     sudo apt install xfce4 xfce4-goodies dbus-x11 -y
    
     # Install TigerVNC Server
     sudo apt install tigervnc-standalone-server -y
    
     # VNC 配置密码
     vncpasswd
    
     # 首次启动、关闭,以生成 xstartup 配置文件
     vncserver
     vncserver -kill :1
    
  2. 配置 ~/.vnc/xstartup

    1
    2
    3
    4
     #!/bin/sh
     unset SESSION_MANAGER
     unset DBUS_SESSION_BUS_ADDRESS
     exec /bin/sh /etc/xdg/xfce4/xinitrc
    
  3. 启动 vncserver

    1
    2
    3
    4
    5
     # 命令行启动
     vncserver -localhost no
    
     # 检查开启的端口是否有 vnc 5901
     ss -tunlp | grep vnc
    
  4. vnc 客户端访问 ip:5901 来连接

    1
    2
     # tigervnc viewer
     sudo apt install tigervnc-viewer -y
    
  5. 配置VNC service
  • /etc/systemd/system/vncserver@.service
    ~~~sh
    [Unit]
    Description=Start TightVNC server at startup
    After=syslog.target network.target

[Service]
Type=forking
User=your-name
Group=your-name
WorkingDirectory=/home/your-name

PIDFile=/home/your-name/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1440x960 :%i -localhost no
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
启动 5901 端口上桌面: `sudo systemctl start vncserver@1.service`


以上配置的 service 无法运行,直接使用 vncserver 命令可以正常启动。

此时,可以修改成如下service 文件:

* `/etc/systemd/system/vncserver@.service`
~~~sh
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=simple
WorkingDirectory=/home/your-name
RemainAfterExit=yes
SuccessExitStatus=0

PIDFile=/home/your-name/.vnc/%H:%i.pid
ExecStartPre=-/bin/su -l your-name -c "/usr/bin/vncserver -kill :%i >> /dev/null"
ExecStart=/bin/su -l your-name -c "/usr/bin/vncserver -depth 16 -geometry 1440x960 :%i -localhost no"
ExecStop=/bin/su -l your-name -c "/usr/bin/vncserver -kill :%i"

[Install]
WantedBy=multi-user.target