Is there any difference between sudo password and the one I used to login?

9,263

Solution 1

sudo, by default, asks for your password, which is the password you use to login. On the other hand su ask for the password of the target user which, unless specified, defaults to root. Note that by default Ubuntu has an invalid password field set for root, effectively making it impossible to login as root.

Solution 2

I was under the impression that both the sudo password and the password that I use to login to Ubuntu are the same.

They are.

If you want a root prompt you need to type

sudo -i

when using the admin account. Mind though: there are not a lot of situations where you should need to use a root prompt and it is more likely you want to do something not the Ubuntu way.

Example (in order: "su", wrong password using "sudo su", correct password):

:~$ su
Password: 
su: Authentication failure
:~$ sudo -i
[sudo] password for xxxxx:
Sorry, try again.    
[sudo] password for xxxxx: 
:/home/xxxxx# 
  • Ubuntu does not have a "root" account (or better: it has been disabled). So "su" does not work since that is tied to the "root" account. "sudo -i" is tied to your admin user and will work.

Solution 3

If you use sudo (usually some command following it) it will ask you your login password, and you will gain root privilege.

when you use su you will be asked root user password (this is not the same as your login password unless you want it to be which is not recommended)

Usually, root user password is not set by default in Ubuntu on fresh install (in fedora you are asked to set root user password during installation). You have to set, only if you want to, root user password after installation.

Here is how you do it:

sudo -i

enter your login password and you will get something like this:

root@computer:/home/edward# 

now type:

passwd

now you will be asked to set root user password.

So they are different thing.

Share:
9,263

Related videos on Youtube

Varun
Author by

Varun

"If you are not falling every now and again, it's a sign you aren't doing anything very innovative." -Woody Allen

Updated on September 18, 2022

Comments

  • Varun
    Varun over 1 year

    I was under the impression that both the sudo password and the password that I use to login to Ubuntu are the same. But it happened that after logging into the system, tying the password in terminal followed by su, it raises Authentication failure ! error. Aren't they the same ?

    • Pilot6
      Pilot6 over 8 years
      They are same..
    • steeldriver
      steeldriver over 8 years
      What exactly did you type? invalid password ! doesn't sound like a normal response from sudo (the standard English-language failure message is Sorry, try again.)
    • Varun
      Varun over 8 years
      @steeldriver oops! i corrected the qn
    • Rinzwind
      Rinzwind over 8 years
      "tying the password in terminal followed by sudo" Please provide the exact command and error. "followed"? I would assume "sudo" preseeds the command
    • Varun
      Varun over 8 years
      @Rinzwind I typed su and then entered the password. But it says authentication error!
    • Rinzwind
      Rinzwind over 8 years
      You need to use sudo su. su is for systems that use a "root" account and Debian styled systems (ie. Ubuntu) do not.
    • Byte Commander
      Byte Commander over 8 years
      @steeldriver Adding the line Defaults insults to your /etc/sudoers file will make the output on mistyped passwords much more interesting... ;-D
    • Edward Torvalds
      Edward Torvalds over 8 years
      @Pilot6 they are not. Read my answer
  • Byte Commander
    Byte Commander over 8 years
    Is sudo su the same as sudo -i?
  • kos
    kos over 8 years
    The reason why su fails is because it expects the root password, and not the user's password; nonetheless passwordless root login through su is disabled for obvious reasons, so the only way to login as root through su is to set root a password
  • terdon
    terdon over 8 years
  • meskobalazs
    meskobalazs over 8 years
    "Your username password and sudo password [are] initially the same". They are always the same.
  • kos
    kos over 8 years
    Or even just sudo passwd
  • kos
    kos over 8 years
    I think the password field is just blank; I can't check my /etc/passwd file because it's unreliable as I've previously set / deleted root's password, however sudo grep ^root /etc/shadow should clarify
  • Admin
    Admin over 8 years
    @kos According to man shadow after setting an empty password field "no passwords are required to authenticate as the specified login name."
  • kos
    kos over 8 years
  • Admin
    Admin over 8 years
    @kos This is true - settings of pam_unix do change the default behaviour. By default in ubuntu using the command you executed should still let you login using the console.