在CentOS上为TigerVNC设置密码的步骤
首先确保系统已安装TigerVNC Server软件包。根据CentOS版本选择以下命令:
sudo yum install tigervnc-server tigervnc -y
sudo dnf install tigervnc-server tigervnc-common -y
使用vncpasswd命令为用户设置VNC访问密码(密码长度至少6位)。此密码会加密存储在用户家目录的.vnc/passwd文件中(与系统用户密码无关)。
vncpasswd
执行后会提示输入密码和确认密码,输入完成后密码即设置完成。
为提升连接安全性,建议启用x509证书加密,步骤如下:
.vnc文件夹,创建x509子目录并复制OpenSSL配置文件:mkdir -p ~/.vnc/x509
cp /etc/pki/tls/openssl.cnf ~/.vnc/
openssl.cnf文件,在末尾添加Subject Alternative Name(SAN),替换your_server_ip为服务器实际IP:sudo vi ~/.vnc/openssl.cnf
在文件末尾添加:[subject_alt_section]
subjectAltName=IP:your_server_ip
openssl req -x509 -newkey rsa -days 365 -nodes -config ~/.vnc/openssl.cnf -keyout ~/.vnc/x509/vnc-server-private.pem -out ~/.vnc/x509/vnc-server.pem
~/.vnc/config,不存在则创建),添加以下内容启用x509加密:securitytypes=x509vnc
x509key=~/.vnc/x509/vnc-server-private.pem
x509cert=~/.vnc/x509/vnc-server.pem
:1对应端口5901):vncserver :1
5901端口已开启):netstat -tunlp | grep 5901
若系统启用了防火墙(如CentOS 7+的firewalld),需放行VNC端口(5901对应:1,5902对应:2,依此类推):
sudo firewall-cmd --permanent --add-port=5901/tcp
sudo firewall-cmd --reload
vncpasswd命令即可。