Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 23639  / 1 Year ago, tue, december 13, 2022, 9:23:25

I am using a script to automatically set up a computer. I need to assign a password to the vnc server for the user, which is normally done using the vncserver command. However, it prompts for the user to enter and re-enter their password, neither of which the script is capable of doing. So, how can I set up the VNC password without an interactive prompt?



Thanks.


More From » bash

 Answers
2

As far as I know, the vncserver command only prompts for a password if the password file (by default, $HOME/.vnc/passwd) is absent - typically the first time it's run for a particular user. You could either script that initial vncserver interaction using 'expect', or pre-create the user's password file by calling the vncpasswd utility via expect before you run vncserver for the first time; e.g. [CAUTION: this is absolutely minimal, you should add some sanity checks if this is used in a serious environment]



#!/bin/sh

prog=/usr/bin/vncpasswd
mypass="newpass"

/usr/bin/expect <<EOF
spawn "$prog"
expect "Password:"
send "$mypass
"
expect "Verify:"
send "$mypass
"
expect eof
exit
EOF


If you don't want to (or can't) use 'expect', then there are various hacks available on the web - VNC passwords apparently use a form of DES encryption so searching with the terms 'VNC' 'DES' 'password' should get you what you need (I'm not going to link here since I cannot vouch for any particular one).



For completeness, note that the default Ubuntu 'Desktop Sharing' uses vino, and the password for that appears to be simply base64 encoded, so it is possible to set it directly e.g.



gsettings set org.gnome.Vino vnc-password "$(echo -n "newpass" | base64)"


Hope this helps


[#30091] Wednesday, December 14, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ormlai

Total Points: 292
Total Questions: 106
Total Answers: 115

Location: Cape Verde
Member since Fri, Sep 16, 2022
2 Years ago
ormlai questions
Wed, Sep 28, 22, 00:17, 2 Years ago
Sun, Aug 7, 22, 22:05, 2 Years ago
Wed, Jun 16, 21, 03:50, 3 Years ago
Sun, Feb 6, 22, 09:11, 2 Years ago
Mon, Jul 12, 21, 10:00, 3 Years ago
;