this post was submitted on 19 Jul 2023
26 points (100.0% liked)

Linux

48052 readers
733 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by AlpΓ‘r-Etele MΓ©der, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Hi everyone πŸ™‚

TLDR

How do you work with debian and su permission and what's the best way to do it for better security?

  • Add an user in the sudoers?
  • Give special permissions to a group? User?
  • Always connect to su - (default root)?
  • Add users to groups?

The story is unrelated to the question, but is a direct cause

This is rookie question even though I use linux (ubuntu and recently debian) regularly and have alot of selfhosted docker containers on an old spare laptop.

While this is probably one of the basics you need to know right away when playing arround with sudo or su I wasn't aware of how you can f#ck everything up with a single command

chmod -R xxx /home/$USER

chown -R ...

Why would you do that? Because I'm stupid and how sometimes no idea what I'm doin? I was actually trying to change some permission to create a samba share (that's another story xD).

Trying to revert everything, alot of my docker containers, certificates and special files were unreadable, unexecutable... That broke my nextcloud instance, synchthing functionalities, linkding http shortcut...

With that big incident, I learned how users, root, sudo/su permission work and recently found out you can add users to groups, like docker so you don't have to 'sudo docker' everytime.

My question

How do you work with debian and su permission and what's the best way to do it for better security?

  • Add an user in the sudoers?
  • Give special permissions to a group? User?
  • Always connect to su - (default root)?
  • Add users to groups?

Because this is in a homelab environment, there is a minimal risk compared to exposed instances, but I'm interested to learn the best practice right away !

Thank you 😊

top 9 comments
sorted by: hot top controversial new old
[–] [email protected] 9 points 1 year ago* (last edited 1 year ago) (1 children)

Being bad at a thing is the first step to being kinda good at a thing.

First, many distros ship with sudo so its pretty ubiquitous, anything you learn about managing sudo will apply to most if not all distros, not just debian. (Great choice though ❀️)

The correct answer is "it depends".

In a production environment you'll typically have some external authentication source like IdM, FreeIPA or active directory set up. In this case its common to just give full sudo access to the group that comprise your admin team, as in most cases you have to trust that they know what they're doing.

Ideally you want to follow the priciple of least access and avoid privilege escalation as much as possible. For example, there may be specific instances where a non-priv user needs to run $x as a super user, in which case, you should only grant the ability to 'sudo' for that executable as opposed to 'ALL'.

As you've already discovered, with great power comes great responsibility. πŸ˜‰

[–] [email protected] 2 points 1 year ago

Thank you for your great insight !!!

[–] [email protected] 8 points 1 year ago (1 children)

Have you read their page about sudo? Gives some pretty good insight. For bonus points, at the bottom of that page are links for security and administration.

https://wiki.debian.org/sudo

[–] [email protected] 2 points 1 year ago (1 children)

Yeah I have it in my favs, but I wanted a direct experience with people who actually know what they are doing and how ! :D

[–] [email protected] 1 points 1 year ago

In my home pc, I don't use sudo because my wife is the main user, and in the ultra rare occasion I need to be root in the command line (for example, if she didn't update packages from the GUI for long, I'll update but I like aptitude better), then I use su. It's a LTS 18.04 Kubuntu btw. Real users don't need root. Distro hoppers and tinkerers (nothing wrong with it) do.

On servers, I also use su. I ssh as a normal user (root ssh is usually disabled), then often immediately su, as if I'm logging into the server, it's for root work. I sometimes su - down to some specific "service" user to do that user's tasks (such as git on a gitlab server, or ndbadm on a HANA DB server).

I only tinker with sudo if I want to create users that will have one single purpose, which needs root permissions, such as restarting a service. In this case that user will be in the sudoers file, with permission for a single script or command, and often that command will be its default shell in /etc/passwd, and someone can ssh (pre shared key) to trigger it if necessary.

[–] [email protected] 4 points 1 year ago (1 children)

There is already a sudo group. Just add a user to it and next time they log in they can use sudo.

[–] [email protected] 1 points 1 year ago

Yep I know that ! But with my badly written question you probably missed my point :(

[–] [email protected] 3 points 1 year ago

@deepdive The ""correct"" answer is "only do root things as root" not via root. But security in more of a human problem than it is configuration.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

In my home pc, I don't use sudo because my wife is the main user, and in the ultra rare occasion I need to be root in the command line (for example, if she didn't update packages from the GUI for long, I'll update but I like aptitude better), then I use su. It's a LTS 18.04 Kubuntu btw. Real users don't need root. Distro hoppers and tinkerers (nothing wrong with it) do.

On servers, I also use su. I ssh as a normal user (root ssh is usually disabled), then often immediately su, as if I'm logging into the server, it's for root work. I sometimes su - down to some specific "service" user to do that user's tasks (such as git on a gitlab server, or ndbadm on a HANA DB server).

I only tinker with sudo if I want to create users that will have one single purpose, which needs root permissions, such as restarting a service. In this case that user will be in the sudoers file, with permission for a single script or command, and often that command will be its default shell in /etc/passwd, and someone can ssh (pre shared key) to trigger it if necessary.

PS: It happened sometimes that I was given a user with full sudo permissions to do root work in someone else's server, but no root password. Then the first thing I do after logging in is "sudo su -" :-)

load more comments
view more: next β€Ί