Master su and sudo: Switch Users Safely and Harness Linux Privileges
This guide explains the differences between the su and sudo commands, shows how to create and manage users, demonstrates login-shell versus non‑login-shell switching, covers the -c option for one‑off commands, and compares security implications of each method in Linux environments.
1. Preparation
Before demonstrating user switching, create a few test users to use later. The Linux command to add a user is useradd, typically found in the PATH. If the command is not found, use the absolute path /usr/sbin/useradd. Only the root user can execute useradd, so switch from the regular ubuntu user to root first:
ubuntu@VM-0-14-ubuntu:~$ su -
Password: # enter root password
root@VM-0-14-ubuntu:~# useradd -m test_user
root@VM-0-14-ubuntu:~# ls /home
test_user ubuntuSet a password for the new user with passwd:
root@VM-0-14-ubuntu:~# passwd test_user
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfullyExit back to the regular user:
root@VM-0-14-ubuntu:~# exit
logout
ubuntu@VM-0-14-ubuntu:~$Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
