[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Su and Sudo in inux

Posted on 2013-12-08
6
Medium Priority
?
481 Views
Last Modified: 2013-12-08
I have been reading about the difference between Su and Sudo command in linux
it says with Sudo, if the user is in the Sudoers file, he will enter the password and he will be able to run a single command. with Su the user will enter the root password and will be able to run any command.

So if I know the root password, then I do not need to run Sudo at all…correct ?
anyone to clear the confusion on this ?

Thanks
0
Comment
Question by:jskfan
6 Comments
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 500 total points
ID: 39704396
the su command requires you knowing root password (in your case) where you want to run  different commands as root, while sudo requires you to enter different password and run specific commands as root.

Please see link below for how to use sudo

http://www.gratisoft.us/sudo/sudoers.man.html
0
 
LVL 88

Assisted Solution

by:rindi
rindi earned 1000 total points
ID: 39704481
With su you are changing to the root user, and therefore after that you can do everything. With sudo you are only elevating the current user's security, it is similar to UAC in windows where you have to agree to running administrative tasks before you are allowed to run them, it's a kind of safety measure so you are warned before you do anything destructive.

On Ubuntu you can't su before you have set a password for root.
0
 

Author Comment

by:jskfan
ID: 39704545
so if you are logged in as root , you do not need to run sudo ?
if you are logged in as regular user, then you type  su to run something  as root, you will stay logged in as root for the rest of the commands that you will run , until you specifically type again su to switch to regular user ???

 if you type sudo to run a command, then after that command is executed , your privileges will go back to the regular user ????

is this correct ?
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 500 total points
ID: 39704603
>>So if I know the root password, then I do not need to run Sudo at all…correct ?

Yes you do not need sudo if you are root. But it is often recommended to login as regular user, sudo to root unless if you need root rights.

For example - sudo su -  allows user to switch to root without exposing the root password. User enter their own password and become root. If the system is being managed or use a large number of users, utilizing sudo is highly recommended.

Take a look of the /etc/sudoers to understand more.
0
 
LVL 88

Accepted Solution

by:
rindi earned 1000 total points
ID: 39704638
"so if you are logged in as root , you do not need to run sudo ?"

Correct, then you already have all the rights on the system.

"if you are logged in as regular user, then you type  su to run something  as root, you will stay logged in as root for the rest of the commands that you will run , until you specifically type again su to switch to regular user ???"

Not exactly. Using "su", you login as root for that terminal session, and you stay logged in as root for that terminal session. To go back to the original user, you type "exit".

"if you type sudo to run a command, then after that command is executed , your privileges will go back to the regular user ????"

Correct, but sudo allows you to streamline the settings in the sudoers file. For example you can limit what applications a user is allowed to run using sudo, and there is usually also a timeout set which allows you to use sudo again for a certain period of time after the first sudo command without requiring the user password. Or you can also allow users to run sudo without even requiring his password.
0
 

Author Closing Comment

by:jskfan
ID: 39705215
Thank you
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question