⌨️ Ubuntu basics user account commands
As working with team as software developer, we have to create multiple users in linux. By default in cloud server provide ubuntu user by default but still sometime we need more user. Here I’m noting down set of commands used for creating user and updating password of users.
Create new user account on Ubuntu Linux
- To add a new user in Ubuntu run
sudo adduser <NewUserName>
. - Enter password and other needed info to create a user account on Ubuntu server.
- New username would be added to
/etc/passwd
file, and encrypted password stored in the/etc/shadow
file. - Once the user is added, we can add it in sudo group with
usermod -aG sudo userName
.
Update password of any existing user account on Ubuntu
- Run command
sudo passwd <userName>
. - To change the password of root user run, above command with userName as root.
- You can directly update the password of logged in user by
passwd
.
Delete user account
- Run command
sudo userdel <userName>
. - To delete home directory and mail spool too, run
sudo userdel -r <userName>
.
Delete user account password:
- Run command
passwd --delete <userName>
. - To verify that password is empty run
grep -w '^UserNameHere' /etc/shadow
, output should something like:realchoubey::19431:0:99999:7:::
. - Recommend to set user shell to nologin to avoid security related problems:
usermod -s /usr/sbin/nologin <userName>
Screen:
Many times we need to run long running commands, as ssh shell timeout after certain time the process also breaks and tasks which we were looking to complete also breaks. To avoid that we can use Screen in linux. Below are the commands that can be used:
- Install command:
sudo apt install screen
- Start screen with some name of screen:
screen -S realchoubey-session
- To get out of screen session or in more technical term to detach from screen press
Crtl+a+d
use commandscreen -d realchoubey-session
. - Once you are out, run
screen -ls
to list all the screen running - To reattach or resume screen session, we can use -r option. Command will look like
screen -r realchoubey-session
. - Once your work is done don’t leave screen session, kill it with below command
screen -XS realchoubey-session quit
Everywhere I have used name for session, but if you forget to give name to session then also you can do all above operations using PID, which can be get with
~$ screen -ls
There is a screen on:
21956.pts-0.ip-172–31–35–193 (04/23/23 07:35:39) (Detached)
21956 is the PID of session we can be used in place of session name, which is realchoubey-session
in examples.