Linux User Switching

LinuxLinuxBeginner
Practice Now

Introduction

Welcome to the Supernatural Academy for the technologically gifted, where the elite hackers and code whisperers of tomorrow sharpen their skills. Within these mythical walls lies a challenge that will test the practical abilities of our most promising student: you!

Your mission, should you choose to accept it, is to navigate the cryptic corridors of Linux user environments and harness the power of user switching. As your initiation, you will master the subtle art of su (substitute user) and prove your worth to the grandmasters of code. This will not only enhance your terminal wizardry but also prepare you for the dire circumstances where you must seamlessly morph from one user identity to another.

Are you ready to accept this challenge and join the pantheon of Linux luminaries?


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/UserandGroupManagementGroup -.-> linux/su("`User Switching`") subgraph Lab Skills linux/su -.-> lab-271391{{"`Linux User Switching`"}} end

Understanding su and Switching Users

In this step, we will explore the enchanted forests of user accounts by employing the su command. You'll learn to transform into another user, granting you their powers and perspective on the system. Begin your journey by creating a new user named 'apprentice' and grant it the power of 'sudo'.

sudo adduser apprentice
sudo usermod -aG sudo apprentice

Now, as a magical incantation allows a wizard to assume various forms, so does the su command allow you to switch users:

su - apprentice

This command will prompt you for 'apprentice's password. Upon successful entry, your terminal environment will change to that of the 'apprentice'.

In the shell environment of 'apprentice', create a file named ~/project/apprentice-journal.txt and write your first impressions:

mkdir -p ~/project
echo "This is my first switch into the user 'apprentice'." > ~/project/apprentice-journal.txt

Switch back to your original user

Having completed an essential task as 'apprentice', it's time to revert to your original form. The ancient rite of user switching is a reversible spell. To relinquish the powers of 'apprentice' and return to your original user, simply exit the current session:

exit

Your terminal will now return you to your primary user's perspective. Verify the switch back by checking your user identity:

whoami

Now let's ensure you've left a trace in the 'apprentice-journal.txt'. Check its contents:

cat /home/apprentice/project/apprentice-journal.txt

Summary

In this lab, we ventured into the realm of Linux user management by using su to switch between different user accounts. We've familiarized ourselves with the process of creating users, switching to a new user context, and reverting back to our original identity. By invoking su and leaving our mark as the 'apprentice,' we've developed practical skills that will aid us when working with multi-user Linux environments.

May you carry forth this arcane knowledge into your future endeavors, and may your path be forever enlightened by the power of the terminal. The Grandmasters of Code will surely recognize your newfound prowess!

Other Linux Tutorials you may like