- 积分
- 16843
在线时间 小时
最后登录1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
Installing VNC Server
2 G3 L* h5 d7 M安装vncserver+ z, q- H; f1 N7 `
TigerVNC is an actively maintained high-performance open-source VNC server. It is available in the default CentOS repositories. To install it, type:0 K; e, X+ Q; w1 ~# a# O# s
7 h# e+ i: b* _7 {
#dnf install tigervnc-server -y" n/ ` t* w: L
- l; {" x* D; Z' U% c9 f配置vncServer
- r8 t8 S' ^! U2 o2 S- A. S" NConfiguring VNC Server
( Z8 g, l+ a* e. GIn CentOS 8, TigerVNC is configured using the systemd daemon.4 j5 L9 }8 s: F* m5 w
/ b& d- [; @* J/ l8 G( ~4 d
0 ^; p P" d3 G" u l/ E. C% TIn this example, we’ll show you how to configure TigerVNC for one or more VNC users.
% X3 T! F; y. ?+ b* R! E7 b+ B
- B3 c. `6 ^! U, B6 zUse the vncpasswd command to set up the password. Run the command as the user that will access the VNC server, do not use sudo:; U# b4 j ~( G- o6 [
这里配置vnc的密码: (root)
& ~2 U; j ~' Q- P K/ u1 i- Vvncpasswd: v8 I& E; r* ? D
& W3 |( P, o4 p4 r. N# ^* Y1 y/ t2 V: y+ E5 U6 _
You will be prompted to enter and confirm the password and whether to set it as a view-only password. If you choose to set up a view-only password, the user will not be able to interact with the VNC instance with the mouse and the keyboard. { v" _( ~5 ]8 d' [2 d) F
* {4 Y7 O3 X/ K: C! V8 z7 T
The first time the vncpasswd command is run, it will create and store the password file in the user’s ~/.vnc directory.
, @9 ^# F- S- f) g5 s! [. `5 y% \, J* R4 a: c) J
Password:! Y2 D6 P5 J( T
Verify:% w, ?6 I, l$ P, _/ H/ ~+ ^4 \- P8 e
Would you like to enter a view-only password (y/n)? n
: T* I8 Y/ K- Z* a6 `7 G3 xA view-only password is not used
0 [6 k# \( M$ `0 u5 h0 A* A- w
% C+ G9 t7 Z0 `* Y
0 Q. P* x& x# E' N: R2 H, l7 vIf you’re adding a second user, switch to it and set the password with vncpasswd.! v0 U8 G$ l4 a$ s1 F
6 b1 [* x/ h$ F, VThe next step is to configure TigerVNC to use Gnome. VNC reads the user configuration settings from the ~/.vnc/config file. Open the file and add the following:$ Y& |8 L) ?( f0 t M5 V( `! H
9 s. f; E4 J7 t% P l
#vim ~/.vnc/config" N9 y3 V1 f' m* k: g4 q) x+ p9 ^+ |
session=gnome0 A o' f/ a) r/ M: ~. V
geometry=1920x1200 (or 1280x720) n9 B) m/ E5 [# @+ q
localhost (这个地方不配置,表示所有的都能访问)
0 Q4 Y3 D6 j- |" d* ^1 Ualwaysshared
5 d6 M: I1 o8 ^% p, T1 A# n) V
" o' N9 _% J7 E3 ^" @例如:
% j) z8 [" L/ N; t) H' X
1 O. b2 t; \! A2 h" Y9 T H9 B$ cat ~/.vnc/config 7 s, X/ Z2 L" H% m3 B) O
session=gnome# W. [1 f- u6 M9 |
geometry=1280x720: n+ q S3 N; V# l0 j6 x, E
alwaysshared; `" \; C W( K5 F5 D0 H$ l
( I/ I- z' E2 T3 ?
- H! ^ e9 }( N1 M$ B
7 P: f) `1 F0 J! U& a5 K' xThe session option specifies the session you want to start, and the geometry option specifies the size of the VNC desktop.
# F! y" @9 {7 W) v. A* q$ o( U5 ^+ ]3 C' X# T* p& Q
Save and close the file . If you’re adding multiple users, repeat the same step.
' N. r3 ^* n6 [7 P: W
. I( d1 V7 N" H4 w) |% pTigerVNC ships with a file that allows you to map a user to a particular port. The mapping is configured in the /etc/tigervnc/vncserver.users file:
; V2 t9 G0 `0 n- U; J& Q. d. l& m
配置vnc的用户:5 F2 E, [$ b6 q; N
4 D+ k( S7 q' v* t8 d) ?. ]
#sudo vim /etc/tigervnc/vncserver.users& A" F8 T% }& F. b% ?
& a0 p5 r `8 W! u- u% `
The file uses <display_port>=<username> syntax. In the example below, we are mapping display port :1 to user linuxize. Use the same format to add more users.
|" x6 _6 b8 J4 P0 A5 c7 C; |' y
/ F2 L3 k2 ?9 [# TigerVNC User assignment
8 o0 Q/ f" q6 F$ z i#
6 w/ P# E- M4 @$ y7 `# This file assigns users to specific VNC display numbers.$ M! q- W1 `# x4 S) I# |3 g
# The syntax is <display>=<username>. E.g.:
1 D6 C" J4 d1 m" \( ]#8 [; c' G7 g- Z/ C' k) ?* m& N8 B
# :2=andrew0 w) K/ k {' v B5 E
# :3=lisa
& R7 c' \1 x: e" x; A6 E:1=root4 d6 H7 L3 @( k- ?) r' G \
3 ]- j* ~4 H/ \* e$ v8 Q
5 l0 P/ p1 o# p! C8 u0 ]' h! B7 F5 ^
. A8 W0 G$ N P) ~3 z+ \6 z7 W:1 is the display port number on which the VNC server will run. In our case, the server is running on TCP port 5901 (5900+1). If you map another user, for example, to display port :2, the server will also listen on port 5902 (5900+2).
5 T6 ]3 l1 G+ O b! v6 c( @, {4 ~5 Y$ [: h: ?3 @
What is important to understand is that when working with VNC servers, :X is a display port that refers to 5900+X.
+ }- z' T" z9 ]# j3 I8 O+ F3 F" A' h8 N; O1 [' y7 S: ^
启动vncserver1 J* ?7 |6 K ?+ Z8 c" {5 j
Starting the Tigervnc Server
3 }4 B- q/ Q# N( \7 b) k k, D3 mOnce you’re done with the configuration, the last step is to start the VNC server.
+ B8 d/ `/ j" J" T9 m1 L- Y8 V# y! l: `
To start and enable the VNC service for the user mapped to the display port :1, enter:5 m- {" ]! q+ Y. P- q
0 ?. o! L0 h: i/ g" S; F" Z6 k. {
复制配置文件:
" Y- r4 w4 u g& s8 i$ ?- d4 u2 e: D7 v
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
1 l0 \$ h! R0 ]
: U& l/ ^* S5 X启动并加入开机启动:
' d* Q( f+ N2 B( { y4 csudo systemctl enable vncserver@:1 --now- {) V3 G4 V" z0 Y
) P$ m+ E3 s3 O7 J
The VNC server will listen on port 5901, as we discussed in the previous section.: c! i- v8 k8 V* P2 `, G4 o9 s
8 f: y1 H0 _. q8 m4 IYou can verify that the service is successfully started with:0 Y5 t9 a" A' i- J9 s# O( W
+ i' S* W- Y- k3 G' Q
+ E2 H" b4 e1 ]* V5 x( q( [0 Ksudo systemctl status vncserver@:1+ \" M! z2 U& K* D
* y* D8 _# l: ]! `- e# Y; l2 n. i
● vncserver@:1.service - Remote desktop service (VNC)
+ G, @6 \' u9 a) `8 L/ J0 O! e Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; enabled; vendor preset: disabled)! Q* H9 ^! W! j G& G2 h
Active: active (running) since Thu 2020-12-17 21:49:41 UTC; 8s ago3 s9 l1 J: k/ q0 t7 T8 G
...+ s# `6 q6 Q# x( v8 J0 N- o
9 Q) \$ y7 @( G( `
To enable VNC for other users, simply replace 1 with the display port mapped to the user./ y$ B2 ?" U4 J; E) l
+ u5 A% a V% p* ~& k2 l+ xConnecting to VNC server h* O! V1 y, I( c
VNC is not an encrypted protocol and can be subject to packet sniffing. The recommended approach is to create an SSH tunnel to securely forward traffic from your local machine on port 5901 to the remote server on the same port.
) a; V4 ^* e" \8 h
# n6 I9 y5 T/ s7 Q. i/ ^
* L( X) n4 c7 @$ r3 ]Set Up SSH Tunneling on Linux and macOS* H2 e v* L2 Z b8 x
If you run Linux, macOS, or any other Unix-based operating system on your machine, you can easily create a tunnel using the following ssh command:3 }- a8 Z6 h& K- a7 A
/ ?! ^# H4 Q: t, n6 ossh -L 5901:10.16.68.5:5901 -N -f -l username remote_server_ip5 ~) q2 P- y* J6 w
Copy
; G+ c" O" _' U) |You will be prompted to enter the user password.
2 c! R3 y& ?* p
8 e% p! f( M6 ^, v: N ]8 R S. Y/ MDo not forget to replace username and server_ip_address with your username and the IP address of your server.# D7 R' b+ ^' Y2 s, g
6 u, R! P% @ x$ i5 D1 V |
|