Understanding Linux Superuser Commands

0

Hey there, fellow SysAdmins and Linux fans! Today, we're diving into a topic that might confuse some of us – powerful commands in Linux. Whether you're a sysadmin, devops, or just starting with Linux, knowing these commands can make you more effective and boost your computer skills. So, let's explore together and understand the world of Linux superuser powers.


Imagine you're working on your Linux system, doing something that needs more control than your usual account allows. Maybe you're updating the system or adjusting settings that regular users can't touch. This is where superuser privileges come in handy. The tricky part? There are lots of commands, each doing something special. But don't worry, we're here to explain them and turn these commands into your digital friends.


Types of Linux Login Shells

Before we jump into the commands, let's lay the groundwork by understanding the types of Linux login shells:-

Login Shell: Requires a username and password for system entry.

Non-login Shell: Executes without formal login, typically for an already logged-in user.

Interactive Shell: Allows real-time command interaction.

Non-interactive Shell: Often run from automated processes, with no visible input or output.


1. Linux `su` Command:

The `su` command allows user switching without changing the current directory. Here's a quick example:

user1@pc$ su user2

Password:

user2@pc$ pwd

user2@pc$ /home/user1  --> User directory remains the same.


2. Linux `su -` Command:

Unlike `su`, `su -` not only switches users but also changes the home directory:

user1@pc$ su - user2

Password:

user2@pc$ pwd

user2@pc$ /home/user2  --> User directory changes.

 

3. Linux `sudo` Command:

Empowering you to run commands with root privileges, using your user password:

user1@pc$ sudo apt-get update

[sudo] password for user1:


 4. Linux `sudo su` Command:

Similar to `su`, `sudo su` facilitates user switching without altering the directory:

user1@pc$ sudo su user2

Password:

user2@pc$ pwd

user2@pc$ /home/user1  --> User directory stays the same.



5. Linux `sudo su -` Command:

This command combines user switching with a change in the home directory:

user1@pc$ sudo su - user2

Password:

user2@pc$ pwd

user2@pc$ /home/user2  --> User directory changes.



6. Linux `sudo -s` Command:

Running a shell with root privileges while keeping your current environment:

user1@pc$ sudo -s

Password:

root@pc:/home/user1# pwd

root@pc:/home/user1# /home/user1  --> User directory stays the same.


7. Linux `sudo -i` Command:

Similar to `sudo su -`, `sudo -i` opens an interactive login shell, changing the user's home directory to root:

user1@pc$ sudo -i

Password:

root@pc$ pwd

root@pc$ /root  --> User directory changes to root.


8. Linux `sudo /bin/bash` Command:

Executing `sudo /bin/bash` maintains your environment while granting root access.


Antim Wakyamsa:

At first, these commands might seem confusing, like a maze. But don't worry! For SysAdmins or Linux fans, knowing when and how to use these commands will not only make your jobs easier but also give you more control in the Linux superuser world.

Post a Comment

0Comments
Post a Comment (0)