top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between sudo su and su?

+1 vote
988 views

As far as i know,

sudo su command will give root login but it will ask for user password,

su command will give root login but it is asking different password

What is the difference between this 2?

posted Sep 1, 2015 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

First lets understand what is sudo
sudo is used to run a command with root privilege.

Now when we run the command "sudo su" it means we are running a single command or we can say

sudo su only changes the current user to root. Environment settings (like PATH) remain the same.
su creates a fresh environment as if root had just logged in (i.e. creates a new shell).

answer Sep 1, 2015 by Salil Agrawal
As you said "sudo" is used to run a single command in root privilege,
So, "sudo su" here we can consider "su" as a command , right?
Then Why different behavior when i run same command ?

So, does it mean "sudo su" is asking user password and "su" is asking root password?

I am still confused with "sudo"
Because if i am executing some command under root privilege then why it is asking user password why not root password?

Right?
Thanks sir, for always helping
Hi Chirag,
Your root and user password might be the same. Please check it once.

As Salil said, sudo doesnt load the root environment variables(like PATH, LD_LIBRARY_PATH and others), bash profile(.bashrc) etc.. Once your command executed, no need to do exit to come back to your user shell. You are already in user shell.

"su" will load a new shell over the previous shell(hence giving different environment variable values)..you will need "exit" command(or Ctrl+D) from that shell to come back to user shell.
Hi Shobhit, Thanks,

When i execute only "su" and enters a password then it is showing wrong password,
Where as in "sudo su" it takes the password(Same as user password)

Any reason behind that?
+1 vote

‘su‘ forces you to share your root password to other users whereas ‘sudo‘ makes it possible to execute system commands without root password. ‘sudo‘ lets you use your own password to execute system commands i.e., delegates system responsibility without root password.

answer Sep 3, 2015 by Avinash Ks
Similar Questions
+2 votes

When I install any Software or tool in Linux by terminal it says you need to update using

sudo apt-get update

Then I get a list of upgrades available in my Linux.

What is the difference between 'Update Manager' and terminal 'sudo apt-get update'?

+3 votes

When I tried to run this kind of script unless I exit rest of the script is not getting executed.

0 votes

What is the relation of "apt-get install" with "apt-get update" ? What exactly "sudo apt-get update" does ?

0 votes

1.If a user want to login with user-id like given below in example,(other than root),then where to make changes?
If I put this question in other way
2.I can login as root but not with my ID(throwing error "Unknow id:")as given below, then where and what to make some changes?

su joydutta
Unknown id: joydutta

0 votes

What is the best way to give root privileges and also log their activity logs. What I did was I have created a user added to group assigned admin rights to the group using entry:-

%group_name ALL = ALL ALL

It works but first time it asks password and it also logs that and after that it dose'nt ask for password and works without giving sudo command

In the next scenario it asks for sudo before any command and logs it without sudo asking for password

I need to work it like it asks for password first time with sudo and then dont need sudo to be added before a command and also logs it.

we use mostly Fedora 15 and CentOS 6.0 up versions on servers.

...