root command create user vnc password

Issues related to applications and software problems and general support
Post Reply
neuronetv
Posts: 79
Joined: 2012/01/08 21:53:07

root command create user vnc password

Post by neuronetv » 2021/01/26 15:53:57

I'm creating a bash script that installs and sets up vnc server on centos 8. When i did this on centos 7 I used:
runuser -l tony -c vncserver <<EOF
<password>
<password>
EOF


however that won't work on centos 8, it throws an error:
vncserver has been replaced by a systemd unit.

the normal manual method to create a vnc password is easy, it's just:
$ vncpasswd
Password: <password>
Verify: <password>
Would you like to enter a view-only password (y/n)? n
A view-only password is not used


but I need to create the vnc password using a script running as root.
whats the correct command to do this?

sml
Posts: 225
Joined: 2020/01/17 09:01:44

Re: root command create user vnc password

Post by sml » 2021/01/26 15:57:48

vncpasswd has option -f for this.

neuronetv
Posts: 79
Joined: 2012/01/08 21:53:07

Re: root command create user vnc password

Post by neuronetv » 2021/01/26 16:07:54

thanks but that doesn't help in working out the correct commands to put in the script

sml
Posts: 225
Joined: 2020/01/17 09:01:44

Re: root command create user vnc password

Post by sml » 2021/01/26 16:22:30

Code: Select all

su - tony -c bash -c 'd=.vnc;mkdir -p $d;vncpasswd -f >$d/passwd <<<password;chmod -R go= $d'
Last edited by sml on 2021/01/26 17:48:23, edited 2 times in total.

User avatar
TrevorH
Forum Moderator
Posts: 30358
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: root command create user vnc password

Post by TrevorH » 2021/01/26 16:42:29

I'm pretty sure that vncpasswd creates the ~/.vnc directory if it doesn't exist.
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

sml
Posts: 225
Joined: 2020/01/17 09:01:44

Re: root command create user vnc password

Post by sml » 2021/01/26 16:48:48

@TrevorH. Not in this case though. vncpasswd -f just outputs the encrypted password to stdout. It's bash redirection that actually writes it to ~/.vnc/passwd.

@OP. Another point. On CentOS, /etc/pam.d/su is configured in such a way that, when used by root, su - user -c command behaves exactly the same as runuser -l user -c command. I changed my previous post to reflect this.
Last edited by sml on 2021/01/27 13:10:39, edited 1 time in total.

neuronetv
Posts: 79
Joined: 2012/01/08 21:53:07

Re: root command create user vnc password

Post by neuronetv » 2021/01/27 11:11:22

thankyou sml that command you gave worked in the script.
strangely enough I also found that
runuser -l tony -c vncpasswd -f <<EOF
# <password>
# <password>
# EOF
worked as well

Post Reply

Return to “CentOS 8 - General Support”