This document is free text: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see
Aimed for Debian 12/11 and Ubuntu 24.04/22.04 Servers
But works fine on Debian, Ubuntu and derivatives' desktops (Ubuntu, Kubuntu, Xubuntu, Lubuntu, MX, Mint etc) too.
Based on the book Mastering Ubuntu Server 2nd Ed. by Jay LaCroix.
sudo useradd -d /home/jdoe -m jdoe
sudo passwd jdoe
sudo userdel jdoe
Remove home directory too
sudo userdel -r jdoe
exforge:x:1000:1000:Exforge,,,:/home/exforge:/bin/bash
username:pw:UID:GID:Name,Surname,XX:homefolder:shell
Passwords are stored as hashed in shadow file
exforge:$6$z09H4l.6$h....A/tDL0:18221:0:99999:7:::
username:pwHash:DatesSinceLastPwChange:MinDaysToChangePw:
MaxDaysToChangePw:DaysBeforeUserWarnedToChangePw:
DaysToPwExpire:DaysToUserDisable
sudo passwd -S username
Contents of /etc/skel folder is distributed to created user's home directory
To give a pw to (and unlock) root
sudo passwd
sudo -i
su - username
sudo su - username
touch users.txt
chmod 600 users.txt
sudo nano users.txt
Fill as below:
user1:password:::User1:/home/user1:/bin/bash
user2:password:::User2:/home/user2:/bin/bash
user3:password:::User3:/home/user3:/bin/bash
#username:passwd:uid:gid:full name:home_dir:shell
sudo newusers users.txt
You can check users from /etc/passwd
sudo passwd user1
groups
or
cat /etc/group
it is similar to /etc/password
sudo groupadd admins
sudo groupdel admins
getent group groupname
-a append new group to groups of user
-G as a secondary group
sudo usermod -aG admins myuser
sudo usermod -a -G admins myuser
or
sudo gpasswd -a <username> <group>
sudo usermod -g admins myuser
sudo gpasswd -d <username> <grouptoremove>
First change home directory
sudo usermod -d /home/jsmith -m jdoe
Then change username
sudo usermod -l jsmith jdoe
sudo passwd -l <username>
sudo passwd -u <username>
sudo chage -l <username>
Members of sudo group can use sudo command
sudo visudo
Opens the sudo configuration file in the default editor (Generally vim or nano)
Below is a sample file with explanations:
%sudo ALL=(ALL:ALL) ALL
# sudo group members
# can use sudo from any terminal
# can use sudo to impersonate any user
# can use sudo to impersonate any group
# can use sudo for any command
charlie ubuntu-server=(dscully:admins) /usr/bin/apt
#__________________________________
# user charlie,
# can only use sudo on ubuntu_server
# can only impersonate dscully user
# can only impersonate admins group
# can only run /usr/bin/apt
# For a user to sudo without passwd
ansible ALL=(ALL) NOPASSWD: ALL
sudo -l