LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-28-2022, 12:06 AM   #1
Alfred-Augustus
Member
 
Registered: May 2022
Posts: 91

Rep: Reputation: 7
Sudo vs Root Login


For home users doing system maintainence, is it safer to use sudo or log-in as root?

I have read it is better to use sudo.

Last edited by Alfred-Augustus; 12-28-2022 at 01:15 AM.
 
Old 12-28-2022, 01:07 AM   #2
henca
Senior Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 1,013

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
I would say there are at least 5 different ways to do this:

1) Log in as root, this is rather OK on a text console, but I avoid logging in as root into some graphical desktop environment like KDE or XFCE.

2) "su -" to become root, this can be done on a text console as well as in some graphical terminal like xterm.

3) Only "su" to become root. This has the disadvantage that the login environment might not become exactly as intended for root as the environment is inherited from the user.

4) "sudo bash" to become root in a terminal. This might be convenient for a user unable to use su, but there will be no real logging of what you have done as root.

5) "sudo command" to run a single command as root. Each call to sudo will be logged in your systems log files.

The only advantage I can come to think of with sudo is that it logs what has been done in the system log files. The disadvantage is that you will need to configure sudo to allow a specific user to run sudo. However, this configuration also allows you to only allow a limited sets of commands to a specific user. To edit the sudo configuration file you will need root privileges.

The advantage with logging in as root or to use su is that it usually involves slightly less typing.

So to summarize:

If you trust a user to do anything on a machine, give that user the root password.

If you only want to allow a user to run a specific set of commands as root, configure that with visudo.

Added to the above 5 ways to become root you might have others like "ssh root@localhost", but those would assume things like that sshd allows root login.

regards Henrik
 
5 members found this post helpful.
Old 12-28-2022, 01:19 AM   #3
Alfred-Augustus
Member
 
Registered: May 2022
Posts: 91

Original Poster
Rep: Reputation: 7
Quote:
Originally Posted by henca View Post
If you trust a user to do anything on a machine, give that user the root password.
Would 6-digits passcode be acceptable as Linux user password? Like how on iPhones and on Windows.


Quote:
Originally Posted by henca View Post

1) Log in as root, this is rather OK on a text console, but I avoid logging in as root into some graphical desktop environment like KDE or XFCE.
So, if I am in KDE, then I would Ctrl-Alt-F2 to a console and then log-in as root. This is safer, right?

Or do I have to exit KDE completely (goto run level 3)?

Last edited by Alfred-Augustus; 12-28-2022 at 01:43 AM.
 
Old 12-28-2022, 02:32 AM   #4
Tonus
Senior Member
 
Registered: Jan 2007
Location: Paris, France
Distribution: Slackware-15.0
Posts: 1,408
Blog Entries: 3

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
6 digits is quite a weak password for something facing the internet or being accessible physically.

I add another way to be root :
Code:
su -c 'command'
This asks for root password and doesn't need any additional configuration.
 
1 members found this post helpful.
Old 12-28-2022, 02:46 AM   #5
pghvlaans
Member
 
Registered: Jan 2021
Distribution: Slackware64 {15.0,-current}, FreeBSD, stuff on QEMU
Posts: 462

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by Alfred-Augustus View Post
So, if I am in KDE, then I would Ctrl-Alt-F2 to a console and then log-in as root. This is safer, right?

Or do I have to exit KDE completely (goto run level 3)?
Personally, I think switching to root in a graphical terminal is safer. That way, even if you leave the computer for a few minutes and forget to log out of the root session, it will still be protected by the screen locker.
 
1 members found this post helpful.
Old 12-28-2022, 02:49 AM   #6
Racho
Member
 
Registered: Oct 2021
Posts: 59

Rep: Reputation: Disabled
Quote:
So, if I am in KDE, then I would Ctrl-Alt-F2 to a console and then log-in as root. This is safer, right?

Or do I have to exit KDE completely (goto run level 3)?
You don't need neither to go runlevel 3 nor Ctrl-Alt-F2. You can run sudo commands or get a root console in a terminal emulator like konsole (Ctrl-Alt-T). It's ok because the desktop graphical environment is not running with root privileges.
 
Old 12-28-2022, 04:22 AM   #7
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,683
Blog Entries: 19

Rep: Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492
Quote:
Originally Posted by henca View Post
If you trust a user to do anything on a machine, give that user the root password.
Surely one reason sudo was invented was that once two people know a secret, it isn't a secret any more. I can keep my password secret because I am the only person in the world who knows it. If there is a second person with that knowledge, he/she can pass it on to a third without my knowledge or permission.

With sudo, the root password remains a secret; users who can be trusted to execute root functions can use their own passwords.
 
4 members found this post helpful.
Old 12-28-2022, 04:40 AM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I have set sudo for my user so I can use dmesg without password
Code:
# cat /etc/sudoers.d/keefaz
keefaz	ALL = NOPASSWD: /bin/dmesg
$ cat ~/.bashrc
alias dmesg="sudo /bin/dmesg"
 
3 members found this post helpful.
Old 12-28-2022, 08:46 AM   #9
hitest
Guru
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware, Debian
Posts: 7,351

Rep: Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750Reputation: 3750
Quote:
Originally Posted by hazel View Post
With sudo, the root password remains a secret; users who can be trusted to execute root functions can use their own passwords.
Yes. Also as the system administrator you can configure sudo so that a user can only execute a defined set of root commands, that is, they can only do things that you allow them to do. This would be valuable if you have multiple users using the same box. There may be some users that you don't want to have full system access.
 
2 members found this post helpful.
Old 12-28-2022, 12:59 PM   #10
henca
Senior Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 1,013

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Quote:
Originally Posted by keefaz View Post
I have set sudo for my user so I can use dmesg without password
If you want to allow all normal users to run dmesg and don't want to mess with sudo for all users, you can create a file

/etc/sysctl.d/dmesg.conf
Code:
kernel.dmesg_restrict=0
regards Henrik
 
4 members found this post helpful.
Old 12-28-2022, 01:07 PM   #11
henca
Senior Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 1,013

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Quote:
Originally Posted by hazel View Post
With sudo, the root password remains a secret; users who can be trusted to execute root functions can use their own passwords.
If that is a concern it can also be solved without sudo by adding more accounts with uid 0 but separate passwords. Example of what /etc/passwd might look like:

Code:
root:x:0:0::/root:/bin/bash
root_ken:x:0:0::/root:/bin/bash
root_jane:x:0:0::/root:/bin/bash
Such a solution will have the same strengths and weaknesses as a sudo solution. On one hand you don't share passwords, on the other hand there are more ways to gain root access for an intruder.

regards Henrik
 
2 members found this post helpful.
Old 12-28-2022, 02:19 PM   #12
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by henca View Post

Code:
root:x:0:0::/root:/bin/bash
root_ken:x:0:0::/root:/bin/bash
root_jane:x:0:0::/root:/bin/bash
But then root_ken or root_jane are able to modify / delete root password, no?
 
Old 12-29-2022, 01:11 AM   #13
henca
Senior Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 1,013

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Quote:
Originally Posted by keefaz View Post
But then root_ken or root_jane are able to modify / delete root password, no?
Yes, and they will also be able to do that if they are given full root privileges any other way.

regards Henrik
 
Old 12-29-2022, 04:56 AM   #14
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,683
Blog Entries: 19

Rep: Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492
Quote:
Originally Posted by henca View Post
Yes, and they will also be able to do that if they are given full root privileges any other way.
Which is why in the old days, sudo was configured so that sudoers didn't have full root privileges, only as much privilege as they required to do their jobs.

I may be wrong about this but I think the first Linux distro to provide full sudo access was Knoppix Live. Then Ubuntu took it up and it became common to give this type of access to the first registered user. I must admit that I do that too with all my distros, but it's probably sloppy practice. I believe our friend Sundialsvc recommends having two user accounts, and doing all your web surfing in the name of the one who doesn't have any sudo rights.
 
1 members found this post helpful.
Old 12-29-2022, 02:02 PM   #15
henca
Senior Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 1,013

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Quote:
Originally Posted by hazel View Post
Which is why in the old days, sudo was configured so that sudoers didn't have full root privileges, only as much privilege as they required to do their jobs.
Yes, that was exactly the point of sudo and it still should be. From /var/log/packages/sudo-*:
Quote:
sudo: sudo (give limited root privileges to certain users)
sudo:
sudo: 'sudo' is a command that allows users to execute some commands as
sudo: root. The /etc/sudoers file (edited with 'visudo') specifies which
sudo: users have access to sudo and which commands they can run. 'sudo'
sudo: logs all its activities to /var/log/ so the system administrator
sudo: can keep an eye on things.
sudo:
sudo: Homepage: https://www.sudo.ws
Quote:
Originally Posted by hazel View Post
Then Ubuntu took it up and it became common to give this type of access to the first registered user.
Ubuntu, which cares less about unix heritage and cares more about point-and-click users took it a step further. Not only do users get full root privileges with sudo by default. On ubuntu, this is the way it has to be as sudo is also the only way to do adminastrive tasks. On ubuntu it is not possible to login to the root account. Is this safer? Well, at least no one will be able to brute force them selves into your machine using ssh by trying passwords for root@yourmacine.net. On the other hand, during the years, sudo has gotten quite a few security updates against CVEs.

regards Henrik
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Differences between Su, Sudo Su, Sudo -s and Sudo -i LXer Syndicated Linux News 0 09-15-2022 07:47 PM
[SOLVED] sudo to user other than root but do not allow sudo to root Westmoreland Linux - Security 4 07-13-2022 01:09 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
'sudo ls /root/monitor/' outputs, 'sudo ls /root/monitor/*' does not stf92 Slackware 10 07-19-2012 05:20 PM
Can't use sudo, only account that's not root is not a sudo'ers [Ubuntu 9.10] randyriver10 Linux - Desktop 1 01-09-2010 07:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration