What does sudo -i or sudo su do?

Quick to answer questions about finding your way around LMDE as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums within the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
szymon1051
Level 2
Level 2
Posts: 88
Joined: Sun Apr 23, 2023 1:18 pm

What does sudo -i or sudo su do?

Post by szymon1051 »

I'm learning Linux and I'm using a virtual machine with LMDE.
I created a new user with adduser, user1.
As part of the lesson, I needed to check the contents of the home directory of user1, but when I use cd /home/user1, I get a reboot.
I tried sudo cd /home/user1 but got that sudo doesn't know the cd command.
https://askubuntu.com/a/291677
https://superuser.com/a/1609743
I discovered that thanks

Code: Select all

sudo -i
or

Code: Select all

sudo su
you can log in with the root account.
And according to the Release Notes https://linuxmint.com/rel_faye.php the root account should be locked "The root account is locked by default."
Can someone explain this in an easy way?
Last edited by SMG on Sat Feb 17, 2024 8:56 pm, edited 1 time in total.
Reason: Moved to LMDE forum.
User avatar
MiZoG
Level 8
Level 8
Posts: 2395
Joined: Fri Jan 26, 2018 8:30 pm
Location: Athens, Greece

Re: What does sudo -i or sudo su do?

Post by MiZoG »

Root account is locked to protect your system from you yourself or any other user with admin privileges going on a rampage.
From thinking that you can use root account as a normal account, log in to it, open browsers, text editors, other graphical apps, save personal files etc. and delete things simply by dragging them to trash-can.
It is a newbie "safety belt".

Otherwise, as you may already have found out, you can run commands with administrative privileges in a variety of ways that fit your workflow and tasks at hand -- WHEN IT IS NEEDED.

Differences between sudo -i & sudo su etc
User avatar
Coggy
Level 5
Level 5
Posts: 642
Joined: Thu Mar 31, 2022 10:34 am

Re: What does sudo -i or sudo su do?

Post by Coggy »

MiZiG's link is a good one. But just bit of background here:
The root account is absolutely all-powerful. The account is locked by not having a valid password. Nobody can get into your machine's root account by password guessing, even trying thousands of passwords per second for years. Either locally, or across the network. That's good.

But if you are able to log into the machine as someone else, then if you have been assigned the right to do so, you can use sudo (Set User & DO something) you can run commands as root. The first user created during the installation always has the right to run anything as root, and if you are going to do several commands as root, then launching a bash command shell makes a great deal of sense. sudo -s does this, just exit when you've finished being root.

The first user has the ability to add other users (after creating them) to the group that grants the right to use the sudo commmand. I don't remember if that's the adm group or the sudo group though. Maybe that depends on whether you are on Ubuntu, Mint or Debian.
User avatar
kc1di
Level 18
Level 18
Posts: 8181
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: What does sudo -i or sudo su do?

Post by kc1di »

this page will explain the difference between sudo and su.
https://www.howtogeek.com/111479/htg-ex ... n-sudo-su/
In Mint there is not root account setup -Though it can be done. For security purposes it is not set up be default. sudo is used to gain root priviledges by the first user (the one set up at install) to accomplish needed functions.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
t42
Level 11
Level 11
Posts: 3747
Joined: Mon Jan 20, 2014 6:48 pm

Re: What does sudo -i or sudo su do?

Post by t42 »

Probably it is just a figure of speech that root account is blocked for security reasons. A user with sudo status has immediate possibility to switch to root terminal with sudo -i. For example, Debian installation by default creates root password and a user is not included in sudo group. Just logging in into GUI is not recommended and considered unsafe. In linked by the OP LMDE Release Notes a root password is created on as needed bases.
It is important to remember that sudo -i and su are not interchangeable. su is a separated binary with different from root terminal functionality. You can spoil your environment disregarding that. Compare this output:

Code: Select all

###### [1] a_user

$ pwd
/home/a_user
$ echo $HOME
/home/a_user
$ echo $USER           
a_user
$ echo $XDG_RUNTIME_DIR
/run/user/1000
$ echo $LC_*
Bin Desktop Documents Downloads Music Pictures Public Templates Videos bin
$ echo $PATH
/home/a_user/bin:/home/a_user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

###### [2] root terminal

$ sudo -i
[sudo] password for a_user:
# pwd
/root
# echo $HOME
/root
# echo $USER 
root
# echo $XDG_RUNTIME_DIR

# echo $LC_*
*
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

###### [3] su

$ su
Password (for root):
# pwd
/home/a_user
# echo $HOME
/root
# echo $USER
a_user
# echo $XDG_RUNTIME_DIR
/run/user/1000
# echo $LC_*
Bin Desktop Documents Downloads Music Pictures Public Templates Videos bin
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

###### [4] su -

$ su - 
Password (for root):

# pwd
/root
# echo $HOME
/root
# echo $USER
root
# echo $XDG_RUNTIME_DIR

# echo $LC_*
*
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
-=t42=-
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: What does sudo -i or sudo su do?

Post by AndyMH »

szymon1051 wrote: Sat Feb 17, 2024 6:20 pm I created a new user with adduser, user1.
You do know you can do this with the GUI application, menu > admin > users and groups?
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
szymon1051
Level 2
Level 2
Posts: 88
Joined: Sun Apr 23, 2023 1:18 pm

Re: What does sudo -i or sudo su do?

Post by szymon1051 »

AndyMH wrote: Thu Feb 22, 2024 7:43 pm You do know you can do this with the GUI application, menu > admin > users and groups?
I'm learning to use linux using ssh. So I don't have that option.
Hoser Rob
Level 20
Level 20
Posts: 11796
Joined: Sat Dec 15, 2012 8:57 am

Re: What does sudo -i or sudo su do?

Post by Hoser Rob »

t42 wrote: Thu Feb 22, 2024 7:37 pm Probably it is just a figure of speech that root account is blocked for security reasons. A user with sudo status has immediate possibility to switch to root terminal with sudo -i. For example, Debian installation by default creates root password and a user is not included in sudo group....
Lot of truth there, I think the real reason a root account isn't set up by default on Mint or Ubuntu is part of their being beginner friendly,

If you're in WIndows the OS will assume you don't know what you're doing and will prevent you from running some terminal commands, even dealing with low level stuff like installing WIndows/creating boot sector/etc.

In Linux, if you log in as root the OS will assume you know exactly what you're doing. As long as what you're doing doesn't violate the syntax rules of the command it will execute it. If what you told it to do will completely trash the OS it will happily do so.

I ran Ubuntu and Mint for years and never once set up a root account. It wasn't necessary.

BTW I run Debian 12 Gnome on my main Linux box now and, at least using the Calamares graphical installer, you don't have to set up a root account any more. I didn't set up one. And I didn't have to put myself into sudoers, obviously. They even offer official live isos with nonfree firmware now.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
Post Reply

Return to “Beginner Questions”