找回密码
 注册
查看: 43|回复: 1

centos8.3安装vncserver服务提供访问

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-10-15 17:00:02 | 显示全部楼层 |阅读模式
Installing VNC Server
5 F/ i, S& `9 Y% U2 V安装vncserver) _9 ]. ]" P9 i. g
TigerVNC is an actively maintained high-performance open-source VNC server. It is available in the default CentOS repositories. To install it, type:3 B, C3 N  u) |5 V( G# c, F# P
1 ]" F$ g8 T, o4 a) F% ^( i
#dnf install tigervnc-server   -y/ f; |9 Q; r, y- F: T" c
9 i0 E& C2 ]4 @: l: e6 Y! s: W
配置vncServer; F1 J1 [; B! u. b
Configuring VNC Server
) I/ n, b" g  z3 `In CentOS 8, TigerVNC is configured using the systemd daemon.4 k' m  O% m% y, U+ x* T  M
# r8 f$ H% i! U. R: L
* ?. f8 P( z- B- y4 b6 N* t
In this example, we’ll show you how to configure TigerVNC for one or more VNC users.6 {+ f7 D9 j8 D, x

/ |+ N% M8 ^4 Q! g# AUse the vncpasswd command to set up the password. Run the command as the user that will access the VNC server, do not use sudo:/ ^7 c1 f; g; r$ x5 @
这里配置vnc的密码:   (root)( Z' S( j7 H4 i! b% c- j  }4 Y
vncpasswd* {! n; U# B) u- B7 G/ S; |
  q% E+ |2 S3 T3 O! j9 S  _+ F

5 L- J4 b4 M# ^0 V% M6 yYou 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.8 T: D, q) c* k: F

% l1 t9 Q6 |( y; @The first time the vncpasswd command is run, it will create and store the password file in the user’s ~/.vnc directory.
9 r! F+ n1 r: d3 E7 ]! E3 t* @- a) \* U2 e5 o
Password:/ a7 I( A3 j1 {/ e; l! h' c- a( H7 m8 w
Verify:
4 i) o. J4 }2 a9 {  X0 KWould you like to enter a view-only password (y/n)? n' h+ T) k) f% p. q/ P: O" b' |& c/ Q# |
A view-only password is not used
8 z1 Y6 ~0 |, n7 X% h$ d1 V% b! G, O& t( ?7 q
' Z/ P- ^% r$ A; ^+ H. W% V; r
If you’re adding a second user, switch to it and set the password with vncpasswd.
1 O. `8 k+ |, B7 g2 h
! q# X# m) i. D9 p# iThe 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:
+ Z9 d4 [" F" {4 E
: W4 U) ?6 y1 e" q7 o! ?: z#vim ~/.vnc/config
& }: A( ?4 ?) Wsession=gnome
2 S% Y; j' C; Y) c2 M& vgeometry=1920x1200    (or 1280x720)( c2 p9 M- p4 t
localhost          (这个地方不配置,表示所有的都能访问)
: Y4 Y, C' l3 ]alwaysshared
1 h1 u; D/ k" V4 n, l0 e3 p, o6 e( X  ?$ @" l& O" g9 y* U+ N1 M
例如:
- r: ?8 ^# i( J4 M. ]7 G$ n1 Y
/ N% V; m+ }: I1 i% o$ d$ cat ~/.vnc/config # o3 V0 x  U$ }* i7 |# {. H5 b5 h
session=gnome) ]) ?+ a, I5 x4 k: [  N, F
geometry=1280x720
4 i5 _# u' U' ^- t$ c+ x8 \alwaysshared1 g' d3 a/ c" M1 q

% F* T: a7 |+ |; I# ~4 w; n. j4 y, Z  ~- O3 ~% z/ ^
9 v! N6 L1 X3 U7 u. ^7 u- l& f- L
The session option specifies the session you want to start, and the geometry option specifies the size of the VNC desktop.
8 v4 d( T% J5 x* e5 v5 [% [- t4 M! Y2 @3 X) ~& ^1 v) u: E( o; C
Save and close the file . If you’re adding multiple users, repeat the same step.3 i1 U* S3 }' g) j
% k- C6 ^. J3 G0 A6 |
TigerVNC 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:% U4 F8 g% d3 L$ l7 G5 h% h' @1 I: |

8 i0 \# ^9 c: M8 o0 m配置vnc的用户:8 `# f1 F: N' _

6 o4 _$ d: {' l#sudo vim /etc/tigervnc/vncserver.users
( o* a& r& f, R5 i7 x
2 E. o, q4 s5 z* K0 ]& C7 \. ~) GThe 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./ n8 U/ q2 Y4 ~  H

6 B8 z& `, L" g7 r0 k# TigerVNC User assignment
3 u% E1 z9 c% `3 s7 J/ k#
7 m8 E5 }* m7 a# This file assigns users to specific VNC display numbers.
! R1 q, i+ o4 U# The syntax is <display>=<username>. E.g.:
) T  }; F% o/ }; T. A* B' q#$ D/ {; ]2 m2 e9 e2 ~, T
# :2=andrew
( ^1 y/ V# g! z0 s7 j/ K/ L# :3=lisa& E) }9 g; F" ~. d! {# g( Y& i
:1=root( b! d& |% o+ `# q

% M7 q& v5 r8 M" z  ?
% h& T) G2 K9 T# d% N3 D+ @9 I
0 q8 T; N( @2 A8 c: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).
* G" [6 ?* Q: r, f( h
  F' F) K# w5 F/ |. L1 z: vWhat is important to understand is that when working with VNC servers, :X is a display port that refers to 5900+X.
( \* |( ?. r. Z9 W% U" U- d& ]. m8 Y0 Y* z0 s. q7 Z
启动vncserver
# j+ {  T" \! S/ t1 jStarting the Tigervnc Server- Y/ N6 z8 v9 o# K' P7 Z) l0 H
Once you’re done with the configuration, the last step is to start the VNC server.
! x0 C4 G! h4 \$ ]) v, Y/ a
5 f' \: A" {5 W) l) M8 ]  tTo start and enable the VNC service for the user mapped to the display port :1, enter:
, M  S% I6 s3 m3 d+ }) v! V8 I: `9 S; r* T
1 ?9 d0 L$ h* t' f5 M
复制配置文件:
! C0 p1 S- Q3 Y3 I- d3 I2 |
$ X/ B( [2 ^! s7 f/ j4 Ucp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service2 @" l- {$ a! u  f5 l

: H1 g0 `) j$ D$ F启动并加入开机启动:
5 b. T! Q& |' j: |( G2 \sudo systemctl enable vncserver@:1 --now/ x0 G8 t  Q: f% ?+ M
) W1 F0 R* w: J3 s. h' m
The VNC server will listen on port 5901, as we discussed in the previous section.2 y. ^9 ^) z7 P$ a& o3 j

, I+ C" r2 j: U1 uYou can verify that the service is successfully started with:: B5 z7 B; l9 q+ t7 r+ @
) u4 a  f. R( J* L

. n, L, k1 V  o+ E+ tsudo systemctl status vncserver@:1; [' d+ I+ ]; Z; u' H/ I/ U
, o7 O6 o  `7 ?
● vncserver@:1.service - Remote desktop service (VNC)
% _  u" y) O/ f- }6 ]( z   Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; enabled; vendor preset: disabled)4 ^* [8 y1 }/ h% x
   Active: active (running) since Thu 2020-12-17 21:49:41 UTC; 8s ago
7 G, c! i6 x) q# D  ...
2 V# d1 S- m$ M# V0 a, ~0 n* Y: w6 W0 }) ?5 Q
To enable VNC for other users, simply replace 1 with the display port mapped to the user.- K8 W" v1 p- M; O

7 \$ e' p) ^. j/ ?* q  HConnecting to VNC server
) v7 B2 w* ~, H! \3 l1 y. e! LVNC 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.
( C# N7 L! l6 e7 [5 I& n, Y
5 }4 p6 `) ^$ x' K8 c
5 @( f% G. Y* y% e: YSet Up SSH Tunneling on Linux and macOS! M. S, B9 u( D; T" G+ u' ]" {
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:
$ i# M, P: w5 E8 y+ o# {/ }9 t: w4 L; j) _7 N6 r9 R/ T8 q( \
ssh -L 5901:10.16.68.5:5901 -N -f -l username remote_server_ip
  ~; s2 x9 j0 ]2 o* dCopy
+ z0 c8 Q, E8 k" wYou will be prompted to enter the user password.
8 Y& I5 ]' Z8 t# h& o* S7 T
& ^7 C" I1 t9 z3 |4 x' WDo not forget to replace username and server_ip_address with your username and the IP address of your server.
2 F5 s" X! Q2 y- t- G$ z/ H/ u3 ^7 U' z0 U* o  y$ ?+ i* ^

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2024-10-15 17:00:03 | 显示全部楼层
然后就可以通港vnc客户端进行访问
% C- h6 \. p- y- x& p4 F$ C/ [或者通过外网telnet ip 5901 这个地址,即可  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 03:06 , Processed in 0.014048 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表