SlideShare a Scribd company logo
1 of 11
SUDO & SU COMMANDS
From : Dr. Meenu Chopra
Su Command in Linux (Switch User)
The su (short for substitute or switch user) utility allows you to run commands with the privileges of
another user, by default the root user.
Using su is the simplest way to switch to the administrative account in the current login session.
This is especially handy when the root user is not allowed to log in to the system through ssh or
using the GUI display manager.
In this tutorial, we will explain how to use the su command.
How to Use the su Command
The general syntax for the su command is as follows:
su [OPTIONS] [USER [ARGUMENT...]]
When invoked without any option, the default behavior of su is to run an interactive shell as root:
$ su
You will be prompted to enter the root password, and if authenticated the user running the command temporarily becomes
root.
The session shell (SHELL) and home (HOME) environment variables are set from substitute user’s
/etc/passwd entry, and the current directory is not changed.
To confirm that the user is changed, use the whoami command:
whoami
The command will print the name of the user running the current shell session:
root
The most commonly used option when invoking su is -, -l, --login. This makes the shell a login shell with an
environment very similar to a real login and changes the current directory:
su -
If you want to run another shell instead of the one defined in the passwd file, use the -s, --shell option. For
example, to switch to root and to run the zsh shell you would type:
su -s /usr/bin/zsh
To preserve the entire environment (HOME, SHELL, USER, and LOGNAME) of the calling user use the -p, --preserve-
environment option.
On some Linux distributions like Ubuntu, the root user account is disabled by default for security reasons.
This means that no password is set for root and you cannot use su to switch to root.
One option to change to root would be to prepend the su command with sudo and enter the currently
logged in user password:
sudo su -
The sudo command allows you to run programs as another user, by default the root user.
If the user is granted with sudo assess the su command will be invoked as root. Running sudo su - and
using the user password is the same as running su - using the root password.
When used with the -i option, sudo run an interactive login shell with the root user’s environment:
sudo -i
sudo -i is basically the same as running su -.
The advantage of using sudo over su is that the root password doesn’t need to be shared among
multiple administrative user accounts.
Also, with sudo you can allow users to run only specific programs with root privileges.
meenu101@meenu101-VirtualBox: - $ useradd user1
Useradd: Permission Denied
Useradd : cannot lock /etc/passwd: try again later;
meenu101@meenu101-VirtualBox:- $ sudo -s
[sudo] password for meenu101:
root@meenu101- VirtualBox : - # passwd
Enter new LINUX Password :
Retype new LINUX Password:
passwd: password updated successfully
root@meenu101- VirtualBox : - # exit
Exit
meenu101@meenu101-VirtualBox: - $ su
Password:
root@meenu101- VirtualBox : /home/meenu101# exit
Exit
meenu101@meenu101-VirtualBox: - $ sudo - i
root@meenu101- VirtualBox : /home/meenu101#
root@meenu101- VirtualBox : /home/meenu101# exit
Logout
meenu101@meenu101-VirtualBox: - $ sudo su
root@meenu101- VirtualBox : /home/meenu101#
root@meenu101- VirtualBox : /home/meenu101# exit
Exit
meenu101@meenu101-VirtualBox: - $ sudo passwd root
Enter new LINUX Password :
Retype new LINUX Password:
passwd: password updated successfully
meenu101@meenu101-VirtualBox: - $ su
Password:
root@meenu101- VirtualBox : /home/meenu101#
root@meenu101- VirtualBox : /home/meenu101# exit
Exit
meenu101@meenu101-VirtualBox: - $ sudo -k
meenu101@meenu101-VirtualBox: - $ sudo user
[sudo] password for meenu101:
root@user- VirtualBox : - # exit
Exit
meenu101@meenu101-VirtualBox: - $ cd /etc
meenu101@meenu101-VirtualBox: /etc $ Vim sudoers
meenu101@meenu101-VirtualBox:
Conclusion
su is a command-line utility that allows you to temporarily become another user and
execute commands with the substitute user.

More Related Content

What's hot

NCSU MGSA Unix Presentation
NCSU MGSA Unix PresentationNCSU MGSA Unix Presentation
NCSU MGSA Unix PresentationJon Ernstberger
 
Provisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com JujuProvisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com JujuThiago Rondon
 
More Depth Commands In Linux - By Vishnu
More Depth Commands In Linux - By VishnuMore Depth Commands In Linux - By Vishnu
More Depth Commands In Linux - By VishnuKanchilug
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonChris Charlton
 
A Brief Introduction to Writing and Understanding Puppet Modules
A Brief Introduction to Writing and Understanding Puppet ModulesA Brief Introduction to Writing and Understanding Puppet Modules
A Brief Introduction to Writing and Understanding Puppet ModulesDavid Phillips
 

What's hot (9)

NCSU MGSA Unix Presentation
NCSU MGSA Unix PresentationNCSU MGSA Unix Presentation
NCSU MGSA Unix Presentation
 
ubunturef
ubunturefubunturef
ubunturef
 
Provisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com JujuProvisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com Juju
 
Basics Ubuntu commands
Basics Ubuntu commandsBasics Ubuntu commands
Basics Ubuntu commands
 
More Depth Commands In Linux - By Vishnu
More Depth Commands In Linux - By VishnuMore Depth Commands In Linux - By Vishnu
More Depth Commands In Linux - By Vishnu
 
Desktop environments
Desktop environmentsDesktop environments
Desktop environments
 
Unix notes
Unix notesUnix notes
Unix notes
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
 
A Brief Introduction to Writing and Understanding Puppet Modules
A Brief Introduction to Writing and Understanding Puppet ModulesA Brief Introduction to Writing and Understanding Puppet Modules
A Brief Introduction to Writing and Understanding Puppet Modules
 

Similar to Sudo & su commands

Sudo User(super user do)
Sudo User(super user do)Sudo User(super user do)
Sudo User(super user do)Shubhamg Gupta
 
Create a sudo user on rhel
Create a sudo user on rhelCreate a sudo user on rhel
Create a sudo user on rhelLinuxConcept
 
How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7VCP Muthukrishna
 
7 unixsecurity
7 unixsecurity7 unixsecurity
7 unixsecurityricharddxd
 
Linux system admin useful commands
Linux system admin useful commandsLinux system admin useful commands
Linux system admin useful commandsali98091
 
Using Unix Commands.pptx
Using Unix Commands.pptxUsing Unix Commands.pptx
Using Unix Commands.pptxHarsha Patel
 
Using Unix Commands.pptx
Using Unix Commands.pptxUsing Unix Commands.pptx
Using Unix Commands.pptxHarsha Patel
 
LinuInterviewQALinuInterviewQALinuInterv
LinuInterviewQALinuInterviewQALinuIntervLinuInterviewQALinuInterviewQALinuInterv
LinuInterviewQALinuInterviewQALinuIntervAbhishekKumar66407
 
Most frequently used unix commands for database administrator
Most frequently used unix commands for database administratorMost frequently used unix commands for database administrator
Most frequently used unix commands for database administratorDinesh jaisankar
 
Users and groups in Linux
Users and groups in LinuxUsers and groups in Linux
Users and groups in LinuxKnoldus Inc.
 
User Management and Privileges - pfSense Hangout February 2015
User Management and Privileges - pfSense Hangout February 2015User Management and Privileges - pfSense Hangout February 2015
User Management and Privileges - pfSense Hangout February 2015Netgate
 
ManagingLocalLinuxUsersandGroups(2)
ManagingLocalLinuxUsersandGroups(2)ManagingLocalLinuxUsersandGroups(2)
ManagingLocalLinuxUsersandGroups(2)Bipul Kumar
 
A Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
A Complete Guide to “useradd” Command in Linux with Examples _ HostbilloA Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
A Complete Guide to “useradd” Command in Linux with Examples _ HostbilloKiyanaSharma1
 
System administration
System administrationSystem administration
System administrationpuspa joshi
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0venkatakrishnan k
 

Similar to Sudo & su commands (20)

Sudo
SudoSudo
Sudo
 
Sudo User(super user do)
Sudo User(super user do)Sudo User(super user do)
Sudo User(super user do)
 
Create a sudo user on rhel
Create a sudo user on rhelCreate a sudo user on rhel
Create a sudo user on rhel
 
Ubuntu root access
Ubuntu root accessUbuntu root access
Ubuntu root access
 
Cent os 5 ssh
Cent os 5 sshCent os 5 ssh
Cent os 5 ssh
 
How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7
 
7 unixsecurity
7 unixsecurity7 unixsecurity
7 unixsecurity
 
Linux system admin useful commands
Linux system admin useful commandsLinux system admin useful commands
Linux system admin useful commands
 
Using Unix Commands.pptx
Using Unix Commands.pptxUsing Unix Commands.pptx
Using Unix Commands.pptx
 
Using Unix Commands.pptx
Using Unix Commands.pptxUsing Unix Commands.pptx
Using Unix Commands.pptx
 
LinuInterviewQALinuInterviewQALinuInterv
LinuInterviewQALinuInterviewQALinuIntervLinuInterviewQALinuInterviewQALinuInterv
LinuInterviewQALinuInterviewQALinuInterv
 
Most frequently used unix commands for database administrator
Most frequently used unix commands for database administratorMost frequently used unix commands for database administrator
Most frequently used unix commands for database administrator
 
Users and groups in Linux
Users and groups in LinuxUsers and groups in Linux
Users and groups in Linux
 
User Management and Privileges - pfSense Hangout February 2015
User Management and Privileges - pfSense Hangout February 2015User Management and Privileges - pfSense Hangout February 2015
User Management and Privileges - pfSense Hangout February 2015
 
ManagingLocalLinuxUsersandGroups(2)
ManagingLocalLinuxUsersandGroups(2)ManagingLocalLinuxUsersandGroups(2)
ManagingLocalLinuxUsersandGroups(2)
 
A Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
A Complete Guide to “useradd” Command in Linux with Examples _ HostbilloA Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
A Complete Guide to “useradd” Command in Linux with Examples _ Hostbillo
 
System administration
System administrationSystem administration
System administration
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0
 
Sandy Report
Sandy ReportSandy Report
Sandy Report
 

Recently uploaded

Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscapingDr. M. Kumaresan Hort.
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxMohamed Rizk Khodair
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 

Recently uploaded (20)

Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 

Sudo & su commands

  • 1. SUDO & SU COMMANDS From : Dr. Meenu Chopra
  • 2. Su Command in Linux (Switch User)
  • 3. The su (short for substitute or switch user) utility allows you to run commands with the privileges of another user, by default the root user. Using su is the simplest way to switch to the administrative account in the current login session. This is especially handy when the root user is not allowed to log in to the system through ssh or using the GUI display manager. In this tutorial, we will explain how to use the su command.
  • 4. How to Use the su Command The general syntax for the su command is as follows: su [OPTIONS] [USER [ARGUMENT...]] When invoked without any option, the default behavior of su is to run an interactive shell as root: $ su You will be prompted to enter the root password, and if authenticated the user running the command temporarily becomes root.
  • 5. The session shell (SHELL) and home (HOME) environment variables are set from substitute user’s /etc/passwd entry, and the current directory is not changed. To confirm that the user is changed, use the whoami command: whoami The command will print the name of the user running the current shell session: root
  • 6. The most commonly used option when invoking su is -, -l, --login. This makes the shell a login shell with an environment very similar to a real login and changes the current directory: su - If you want to run another shell instead of the one defined in the passwd file, use the -s, --shell option. For example, to switch to root and to run the zsh shell you would type: su -s /usr/bin/zsh To preserve the entire environment (HOME, SHELL, USER, and LOGNAME) of the calling user use the -p, --preserve- environment option.
  • 7. On some Linux distributions like Ubuntu, the root user account is disabled by default for security reasons. This means that no password is set for root and you cannot use su to switch to root. One option to change to root would be to prepend the su command with sudo and enter the currently logged in user password: sudo su - The sudo command allows you to run programs as another user, by default the root user. If the user is granted with sudo assess the su command will be invoked as root. Running sudo su - and using the user password is the same as running su - using the root password.
  • 8. When used with the -i option, sudo run an interactive login shell with the root user’s environment: sudo -i sudo -i is basically the same as running su -. The advantage of using sudo over su is that the root password doesn’t need to be shared among multiple administrative user accounts. Also, with sudo you can allow users to run only specific programs with root privileges.
  • 9. meenu101@meenu101-VirtualBox: - $ useradd user1 Useradd: Permission Denied Useradd : cannot lock /etc/passwd: try again later; meenu101@meenu101-VirtualBox:- $ sudo -s [sudo] password for meenu101: root@meenu101- VirtualBox : - # passwd Enter new LINUX Password : Retype new LINUX Password: passwd: password updated successfully root@meenu101- VirtualBox : - # exit Exit meenu101@meenu101-VirtualBox: - $ su Password: root@meenu101- VirtualBox : /home/meenu101# exit Exit meenu101@meenu101-VirtualBox: - $ sudo - i root@meenu101- VirtualBox : /home/meenu101# root@meenu101- VirtualBox : /home/meenu101# exit Logout meenu101@meenu101-VirtualBox: - $ sudo su root@meenu101- VirtualBox : /home/meenu101# root@meenu101- VirtualBox : /home/meenu101# exit Exit
  • 10. meenu101@meenu101-VirtualBox: - $ sudo passwd root Enter new LINUX Password : Retype new LINUX Password: passwd: password updated successfully meenu101@meenu101-VirtualBox: - $ su Password: root@meenu101- VirtualBox : /home/meenu101# root@meenu101- VirtualBox : /home/meenu101# exit Exit meenu101@meenu101-VirtualBox: - $ sudo -k meenu101@meenu101-VirtualBox: - $ sudo user [sudo] password for meenu101: root@user- VirtualBox : - # exit Exit meenu101@meenu101-VirtualBox: - $ cd /etc meenu101@meenu101-VirtualBox: /etc $ Vim sudoers meenu101@meenu101-VirtualBox:
  • 11. Conclusion su is a command-line utility that allows you to temporarily become another user and execute commands with the substitute user.