Adding a new user to the Ubuntu server is very simple. The useradd command may be used in a script to create multiple users very easily. This is a very good bash shell script to create a bunch of users in one go. All you need to do after this is assign new passwords to each user.
#!/bin/bash declare -a array=("joe" "Rajesh" "Smith" "Smithers" "Mark" "Dhopah" "Phil" "Micheal") arraylength=${#array[@]} for (( i=0; i<${arraylength}; i++ )); do sudo useradd ${array[$i]} -m -s /bin/bash -G users done |
Then you will need to set a password for the new user. This command will suffice.
~# echo 'jim:password1' | chpasswd -c SHA256 |
This will give the new user an encrypted password and they are ready to go.
There are ways to generate a user password using the command line.
How to use the Linux command line to generate an absurdly complicated password.
https://securitronlinux.com/bejiitaswrath/how-to-use-the-linux-command-line-to-generate-an-absurdly-complicated-password/.
The password must be very complicated, passwords can be cracked if the password is not complex enough. This is not too hard, so ensure they are complex enough, using numbers and some uppercase letters and other characters.
To list all valid users on your Linux system, use this command, this is assuming the user id number is greater than 1000 and less than 2000. Adjust this to suit your use case.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ awk -F: '{if($3>999 && $3<2000)print $1,$3,$6}' /etc/passwd john 1000 /home/john joe 1001 /home/joe Rajesh 1002 /home/Rajesh Smith 1003 /home/Smith Smithers 1004 /home/Smithers Mark 1005 /home/Mark Dhopah 1006 /home/Dhopah Phil 1007 /home/Phil Micheal 1008 /home/Micheal |
This is how easy it is to work with users on a Linux system, creating new users and adding a bunch of new user accounts.
This is yet another way to list all valid user accounts that can log in.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ getent passwd | awk -F: '{if($3>999 && $3<2000)print $1,$3,$6}' john 1000 /home/john joe 1001 /home/joe Rajesh 1002 /home/Rajesh Smith 1003 /home/Smith Smithers 1004 /home/Smithers Mark 1005 /home/Mark Dhopah 1006 /home/Dhopah Phil 1007 /home/Phil Micheal 1008 /home/Micheal |
And this example will print a set of column headers to the output.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ awk -F: '{if($3>999 && $3<2000)print $1,$3,$6}' /etc/passwd | awk -F, 'NR==1 {print "Username","ID","Directory"} {gsub(/"/,""); print $1,$2,$4}' | column -t Username ID Directory john 1000 /home/john joe 1001 /home/joe Rajesh 1002 /home/Rajesh Smith 1003 /home/Smith Smithers 1004 /home/Smithers Mark 1005 /home/Mark Dhopah 1006 /home/Dhopah Phil 1007 /home/Phil Micheal 1008 /home/Micheal |
If you wish to install a desktop environment on your server, type this command.
~# apt-get install xubuntu-desktop |
This will install the Xfce4 desktop environment. This is not too demanding, good for a virtualised environment such as a Xen client OS or on an older machine. And now you know how to add users and set passwords on an Ubuntu server installation! Have a lot of fun with Linux, it is a very good alternative to Windows on a server.