Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Discussion] Help me understand root and sudo

Here you can discuss every aspect of Debian. Note: not for support requests!
Message
Author
Augie77
Posts: 71
Joined: 2024-03-23 04:05
Has thanked: 19 times
Been thanked: 9 times

[Discussion] Help me understand root and sudo

#1 Post by Augie77 »

During my first install of Debian/Bookworm, I was given the option of setting a root password, or not. Coming from Mint, I knew to use sudo so I chose no root password. I recently needed to use Recovery Mode, which demonstrated the need for a root user. I am perplexed as to the why and why not of sudo and root in the terminal. When to use one over the other? I need some schooling.

CwF
Global Moderator
Global Moderator
Posts: 2741
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 45 times
Been thanked: 206 times

Re: [Discussion] Help me understand root and sudo

#2 Post by CwF »


User avatar
None1975
df -h | participant
df -h | participant
Posts: 1421
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 47 times
Been thanked: 68 times

Re: [Discussion] Help me understand root and sudo

#3 Post by None1975 »

Hello.

Check this
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
pbear
Posts: 384
Joined: 2023-08-27 15:05
Location: San Francisco
Has thanked: 2 times
Been thanked: 63 times

Re: [Discussion] Help me understand root and sudo

#4 Post by pbear »

FWIW, I always enable both sudo and the root account. Which I use depends on the task and my mood.

User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 666
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 88 times
Been thanked: 110 times

Re: [Discussion] Help me understand root and sudo

#5 Post by wizard10000 »

Augie77 wrote: 2024-04-04 15:16...I recently needed to use Recovery Mode, which demonstrated the need for a root user.
I've grumbled about this for quite awhile - Debian's recovery mode requires a root password but Ubuntu's recovery mode does not.

What I do is skip the root password in the installer and set one after first boot. Been doing it that way for years.
we see things not as they are, but as we are.
-- anais nin

Augie77
Posts: 71
Joined: 2024-03-23 04:05
Has thanked: 19 times
Been thanked: 9 times

Re: [Discussion] Help me understand root and sudo

#6 Post by Augie77 »

I appreciate the links and comments. My understanding of su / sudo / root are much clearer now. I am not experienced enough in Linux to have a well formed opinion of the matter, but I have started using su in place of sudo, and am discovering I do not need to append sudo to every command in terminal. I do ponder the need for root in recovery mode for the single user, but do see where it would used be in an office environment where there is a need to protect the hardware and software from unsavoury employees. I suppose the problem is the installer app has no idea if the PC is at a persons home, or sitting in an office, in front of an IT admin.

User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 666
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 88 times
Been thanked: 110 times

Re: [Discussion] Help me understand root and sudo

#7 Post by wizard10000 »

Augie77 wrote: 2024-04-05 12:45...am discovering I do not need to append sudo to every command in terminal
sudo -i will give you as persistent root prompt.
we see things not as they are, but as we are.
-- anais nin

User avatar
pbear
Posts: 384
Joined: 2023-08-27 15:05
Location: San Francisco
Has thanked: 2 times
Been thanked: 63 times

Re: [Discussion] Help me understand root and sudo

#8 Post by pbear »

Off-topic, recovery mode is a useful tool, but you would be better off setting up something with a desktop you can boot from "outside." I use a full install flash drive. A live ISO also works.

Augie77
Posts: 71
Joined: 2024-03-23 04:05
Has thanked: 19 times
Been thanked: 9 times

Re: [Discussion] Help me understand root and sudo

#9 Post by Augie77 »

pbear wrote: 2024-04-05 15:23 Off-topic, recovery mode is a useful tool, but you would be better off setting up something with a desktop you can boot from "outside." I use a full install flash drive. A live ISO also works.
Consider this an open thread where off topic is welcomed, in fact, I would be glad to change the title to 'Help me understand root, sudo and Recovery Mode'. Knowledge is always a good thing and the more I learn, then the more comfortable I am with helping neighbours and others adopt and adapt to Linux.

I have a live .iso of Debian, and a drive with Foxclone that boots, and has a few tools. I feel that one of the biggest hurdles for new users to Linux is how to recover the system without doing a new install, something I frequently see recommended on other sites. We new users tend to not understand the recovery mode or how to get to it, especially in a single boot environment. Recovery Mode is what I want to become familiar with next.

User avatar
pbear
Posts: 384
Joined: 2023-08-27 15:05
Location: San Francisco
Has thanked: 2 times
Been thanked: 63 times

Re: [Discussion] Help me understand root and sudo

#10 Post by pbear »

As far as I'm concerned, there are only two scenarios where it makes sense to use recovery mode. One is where the user knows exactly what to type to get the desired result and recovery mode will be faster/easier than booting a USB repair tool and solving the problem that way. The other is when one doesn't have a USB repair tool, so it's recovery mode or stare at a black screen. By contrast, a desktop booted from USB has a real terminal, a file manager, an internet browser (to research solutions), and various GUI system tools (e.g., Disks and GParted). And, on a full install flash drive, you can set up the internet connection in advance, install drivers, install apps you might find useful, have copies of troubleshooting notes, etc. Plus, of course, it'll serve as a temporary operating system (to access files, email, etc.) while you work on fixing the installed system.

Augie77
Posts: 71
Joined: 2024-03-23 04:05
Has thanked: 19 times
Been thanked: 9 times

Re: [Discussion] Help me understand root and sudo

#11 Post by Augie77 »

I am extremely uncomfortable with recovery mode, due to lack of knowledge and inexperience. I much prefer the USB live boot method. Presently I use the boot USB from Foxclone, I can use the live .iso for Debian as well, I expect.

User avatar
pbear
Posts: 384
Joined: 2023-08-27 15:05
Location: San Francisco
Has thanked: 2 times
Been thanked: 63 times

Re: [Discussion] Help me understand root and sudo

#12 Post by pbear »

The live ISO for whichever version you installed would be much more useful than the Foxclone ISO, which is only designed to create a platform from which to make backups. If you haven't already, take a look at Ventoy. It's a little work to set up, but once up-and-running a breeze to use. No more faffing about burning ISOs. Just copy to the Ventoy drive and boot directly from them. You also can put Foxclone and other utilities on the drive.

Better still, if you have a flash drive at least 30 GB handy, full install is pretty easy. Not suitable for running the OS - flash drives aren't engineered for this sort of thing - but ideal as a recovery tool. You can have both, of course.

CwF
Global Moderator
Global Moderator
Posts: 2741
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 45 times
Been thanked: 206 times

Re: [Discussion] Help me understand root and sudo

#13 Post by CwF »

I use a a spare bay for a spare sata ssd. For temp use without a bay I take it out and use a sata>usb adapter, works fine.

This ssd can be built, upgraded, used while on a proper sata interface. To test it as usb a vm can boot a vfio usb port, not sure how vbox would do this.

You can fit all you need into a gig+ image utilizing an ~8G+ partition on a any size device.

Not for only recovery, when this ssd has extra space for images then it is the 'flasher' capable of booting s system and imaging to/from its primary boot disk.

User avatar
pbear
Posts: 384
Joined: 2023-08-27 15:05
Location: San Francisco
Has thanked: 2 times
Been thanked: 63 times

Re: [Discussion] Help me understand root and sudo

#14 Post by pbear »

CwF wrote: 2024-04-08 16:06 ... not sure how vbox would do this.
As an aside, VBox calls that function raw disk. There's a section about it in the manual and plenty of articles on the internet.
Will say, the QEMU-KVM implementation of USB boot is easier to set up and more flexible in use.

friendlysalmon88
Posts: 50
Joined: 2023-12-08 16:48
Location: Seattle,Wa USA
Has thanked: 3 times
Been thanked: 5 times

Re: [Discussion] Help me understand root and sudo

#15 Post by friendlysalmon88 »

The main reason that Debian give you the option to create a root or superuser account is that i'ts a common Distribution for use on servers such as Web and email server, where you wouldn't want your server to be accessible by regular users. This is commonly done in most distributions such as Ubuntu because they are imed at "new Linux) users. In closing using sudo is actually a good security practice.

cellSeven
Posts: 3
Joined: 2024-04-09 12:49
Has thanked: 1 time
Been thanked: 1 time

Re: [Discussion] Help me understand root and sudo

#16 Post by cellSeven »

I hope I am on-topic enough to entwine my question with questions of the OP, so that the responses to my own add to both his/her and my own clarity.
As a beginner, I can only see that sudo is conventient but seems to add a security risk. Afterall, when the password of the ordinary user with sudo privileges is compromised, immediately allows the attacker to perform root-privileged commands, whereas if the ordinary user does not have sudo privileges, his compromised account cannot utilise sudo so as to execute root-privileged commands. I would rather go through the trouble to execute the su command than use sudo.
To me it seems that sudo or the doas alternative cancel out the security benefit of privilege-hierarchy.

And: What would be the significant difference between su and su -?
Sincerely,

cellSeven

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1420
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 80 times
Been thanked: 191 times

Re: [Discussion] Help me understand root and sudo

#17 Post by steve_v »

cellSeven wrote: 2024-04-10 10:59 To me it seems that sudo or the doas alternative cancel out the security benefit of privilege-hierarchy.
If you enable sudo for any command, sure.
Many arguments for "desktop" use of sudo miss the point entirely, going for either the "root == always bad" or "easier for newbs to only remember one password" angles.

The real purpose of sudo is to delegate limited superuser authority (e.g. only certain commands), on a per-user or per-group basis (and many other features, via PAM plugins). That kind of thing is of course more applicable to servers or mainframes where there may be more than one administrator, or users that need root priveleges for particular tasks.
As always, the details are in the manual pages.

cellSeven wrote: 2024-04-10 10:59What would be the significant difference between su and su -?
Whether you want a login shell (the primary effect of which is whether your environment is reloaded according to the new user id).
Again, this is all in the manual:
-, -l, --login
Start the shell as a login shell with an environment similar to a real login:
'su -' is currently the advised invocation on Debian, as it correctly sets root's $PATH, allowing you to execute things in e.g. /usr/sbin.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

cellSeven
Posts: 3
Joined: 2024-04-09 12:49
Has thanked: 1 time
Been thanked: 1 time

Re: [Discussion] Help me understand root and sudo

#18 Post by cellSeven »

Hello Steve,

I apologise; it looks like I could have done more research. I do not have my intention set on negligence towards present documentation; I hope you understand a newbie can at whiles be a bit bewildered or overwhelmed by said documentation though. Sometimes the data you are looking for simultaneously co-exists with an abundance of information that is presently too advanced for you, and hence seeking understanding through direct human contact can be preferred in order to get a more-tailored answer suited to your present disposition. I especially had this experience with the FreeBSD manual that, though praised, for a newbie actually presents data with a lot of epistemic gaps.
And, thank you indeed for your enlightening answers! I understand that much more now.
Sincerely,

cellSeven

Augie77
Posts: 71
Joined: 2024-03-23 04:05
Has thanked: 19 times
Been thanked: 9 times

Re: [Discussion] Help me understand root and sudo

#19 Post by Augie77 »

Wow ... I did not know all this has gone on since my last post, I have not been receiving emails about this thread, and only sometimes on other threads.

@pbear I appreciate the ventoy link and will take a look at it. My Foxclone is primarily for cloning, and somtimes backups, though it does not like to back up to my USB thumb drives for some reason. It is handy in a pince as an alternate boot, but I do have the .iso for my Bookworm XFCE install.

@CwF my pc has a microATX board and case, so no external slots. I do have a number of USB ports and have thought about using a 500gig USB/SSD from SanDisk or Corsair as a live boot drive.


@steve_v I appreciate the additional clarity on sudo and su, it validates what I thought I understood.

Going to save this post now, we have had high winds and storms most of the day, I have lost power 7 times now. I won't bother to set any clocks until tomorrow morning.

Thanks to all.

Augie77
Posts: 71
Joined: 2024-03-23 04:05
Has thanked: 19 times
Been thanked: 9 times

Re: [Discussion] Help me understand root and sudo

#20 Post by Augie77 »

pbear wrote: 2024-04-08 15:32 The live ISO for whichever version you installed would be much more useful than the Foxclone ISO, which is only designed to create a platform from which to make backups. If you haven't already, take a look at Ventoy. It's a little work to set up, but once up-and-running a breeze to use.
.
.
.
Ventoy was exceptionally easy to install to a 128gig Sandisk Luxe USB thumb drive. The download tar.gz has a GUI executable that once started, you simply pick the drive to install to and then click install. After that I copied over Debian XFCE, Mate, and Cinnamon. Then booted into Cinnamon. The Ventoy worked quite well, it took longer to read a couple of the web pages than to install Ventoy.

Post Reply