Adding multiple users and setting vnc passwords?

General support questions including new installations
Post Reply
emacsx
Posts: 5
Joined: 2016/02/05 04:33:23

Adding multiple users and setting vnc passwords?

Post by emacsx » 2016/02/05 04:39:17

I can add users using the following commands without specifying a group
# useradd USER1
# passwd USER1
password: ******
Retype password:
password: ******

but if I use the following script with a text file (user_list.txt) containing list of user, i.e. one user per line and user name and password separated by a space, will that work? Am I missing something in the script?

=======================
#!/bin/bash
NEW_USERS="/tmp/scripts/user_list.txt"
HOME_BASE="/home/"

cat ${NEW_USERS} | \
while read USER PASSWORD
do
useradd -p ${PASSWORD} -m -d ${HOME_BASE}${USER} ${USER}
done
=======================

user_list.txt content:
=======================
USER1 USER1_PASSWORD
USER2 USER2_PASSWORD
USER3 USER3_PASSWORD
...
USER9 USER9_PASSWORD
=======================

For the same users I have to set the vnc password for each user manually using the following commands
# su - USER1
$ vncpasswd
password: ******
Retype password: ******
$ exit

How can I write a script to read the same text file and set vnc passwords?

emacsx
Posts: 5
Joined: 2016/02/05 04:33:23

How to write a script for setting vnc passwords for multiple

Post by emacsx » 2016/02/07 05:09:37

I managed to get the user add script work, but how to write the following commands in a script for setting vnc password for multiple users? I need to read a text file (user_list.txt) containing list of user, i.e. one user per line and user name and password separated by a space.

# su - USER1
$ vncpasswd
password: ******
Retype password: ******
$ exit

user_list.txt content:
=======================
USER1 USER1_PASSWORD
USER2 USER2_PASSWORD
USER3 USER3_PASSWORD
...
USER9 USER9_PASSWORD
=======================

Emma Taylor
Posts: 58
Joined: 2015/04/11 04:59:25
Location: United Kingdom

Re: Adding multiple users and setting vnc passwords?

Post by Emma Taylor » 2016/03/07 06:25:52

Ability to connect for multiple users:

Create a local user, using the following command:

Code: Select all

sudo adduser hussain
Switch to the newly created user and run vncserver command for it:

Code: Select all

su hussain
vncserver
Move to the home directory and edit the xstartup file:

Code: Select all

cd ~
nano .vnc/xstartup
Modify the file so it looks like this:
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

Code: Select all

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
Now open up the /etc/vncserver/vncservers.conf file as sudo user:

Code: Select all

sudo nano /etc/vncserver/vncservers.conf
Add servers for newly created user by adding something like this:

Code: Select all

VNCSERVERS="1:arbab 2:hussain"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24"
VNCSERVERARGS[2]="-geometry 1024x600 -depth 24"
Restart the service:

Code: Select all

sudo service vncserver restart
Connect with newly created user using tendo:2, Where tendo is my server name.
Enter the password that we created using the vncserver command.
We now have GUI access to our server for newly created user.

To setup users’ VNC password:

Code: Select all

vncpasswd
Edit the /etc/sysconfig/vncservers file:

Code: Select all

sudo nano /etc/sysconfig/vncservers
Add the following to the end of the file:

Code: Select all

VNCSERVERS="1:arbab"
VNCSERVERARGS[1]="-geometry 1024x600"

Post Reply