Kali 安装vnc

1.安装tightvnc

#apt install tightvncserver
#apt install tightvnc-java #通过浏览器java访问需要安装tightvnc-java

2.启动VNC服务
# vncserver :1  
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服务:

# vncserver -kill :1
4 编辑 xstartup 文件

VNC 服务读取 ~/.vnc/xstartup 文件(功能类似于 .xinitrc),定义一个桌面环境来启动。

# cp .vnc/xstartup .vnc/xstartup.backup
# vncserver -kill :1

编辑~/.vnc/xstartup内容如下,用自动生产的文件远程时候会灰屏,没有图形界面。

# vim ~/.vnc/xstartup
#unset SESSION_MANAGER  
#/etc/X11/xinit/xinitrc  
# chmod u+x ~/.vnc/xstartup
5.修改VNC访问的密码

使用命令vncpasswd对不同用户的VNC的密码进行修改,一定要注意,如果配置了不同用户的VNC需要分别到各自用户中进行修改,例如在我的这个实验中,laopi用户需要修改,修改过程如下:

# vncpasswd
Password:                                             #输入密码
Verify:                                                   #确认密码
6.自启动
 # vi /etc/systemd/system/vncserver@.service
 
[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
# systemctl daemon-reload
# systemctl enable vncserver@:1.service     

不用更改其他的配置
[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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值