1.安装tightvnc
#apt install tightvncserver
#apt install tightvnc-java #通过浏览器java访问需要安装tightvnc-java
2.启动VNC服务
You will require a password to access your desktops.
Password:
Warning: password truncated to the length of 8.
Verify:
Would you like to enter a view-only password (y/n)? n
Warning: debian:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server debian:1
New 'X' desktop is debian:2
Creating default startup script /home/laopi/.vnc/xstartup
Starting applications specified in /home/laopi/.vnc/xstartup
Log file is /home/laopi/.vnc/debian:2.log
如果在Root用户下执行 vncserver :1命令,这样会让普通用户登录时候输入用户名和密码,屏幕黑了一下,然后又返回了输入用户名密码的界面,因为普通用户主目录下的.Xauthority(~/.Xauthority)文件的所属组和所有者都改成了root ,只有把这个文件改回为普通用户所有者和所属组,普通用户才能正常登录。
VNC服务运行的默认端口是 :1 ,它代表服务运行的TCP端口(5900+n = 端口号)。在此例中,它运行在 5900+1=5901 。再次执行VNC服务会创建另一个实例,并运行在下一个更高的空闲端口上,例如 :2 或说 5902。
3.VNC端口号与桌面号
VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下
桌面号为“1” ---- 端口号为5901
桌面号为“2” ---- 端口号为5902
桌面号为“3” ---- 端口号为5903
……
基于Java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下
桌面号为“1” ---- 端口号为5801
桌面号为“2” ---- 端口号为5802
桌面号为“3” ---- 端口号为5803
使用 -kill 开关来关闭VNC服务:
4 编辑 xstartup 文件
VNC 服务读取 ~/.vnc/xstartup 文件(功能类似于 .xinitrc),定义一个桌面环境来启动。
编辑~/.vnc/xstartup内容如下,用自动生产的文件远程时候会灰屏,没有图形界面。
5.修改VNC访问的密码
使用命令vncpasswd对不同用户的VNC的密码进行修改,一定要注意,如果配置了不同用户的VNC需要分别到各自用户中进行修改,例如在我的这个实验中,laopi用户需要修改,修改过程如下:
Password:
Verify:
6.自启动
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
[Service]
Type=simple
User=root
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1024x768 %i
[Install]
WantedBy=multi-user.target
不用更改其他的配置
[root@localhost soft]# vncserver -geometry 1920x1024 -depth 24 :1
[root@localhost soft]# vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:2 8490
[root@localhost soft]# ps aux | grep vnc
root 8490 3.3 1.8 247348 73908 pts/3 Sl 16:38 0:01 /usr/bin/Xvnc :2 -auth /root/.Xauthority -depth 24 -desktop localhost.localdomain:2 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1920x1024 -pn -rfbauth /root/.vnc/passwd -rfbport 5902 -rfbwait 30000
root 8500 0.0 0.0 113292 2548 pts/3 S 16:38 0:00 /bin/sh /root/.vnc/xstartup
root 9112 0.0 0.0 112824 2312 pts/3 S+ 16:38 0:00 grep --color=auto vnc
[root@localhost soft]# ss -tnalp | grep vnc
LISTEN 0 5 :5902 : users:((“Xvnc”,pid=8490,fd=9))
LISTEN 0 128 :6002 : users:((“Xvnc”,pid=8490,fd=6))
LISTEN 0 5 [::]:5902 [::]: users:((“Xvnc”,pid=8490,fd=10))
LISTEN 0 128 [::]:6002 [::]: users:((“Xvnc”,pid=8490,fd=5))
————Blueicex 2020/07/15 17:49 blueice1980@126.com
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)