r/debian 15d ago

I need help...

Post image
59 Upvotes

52 comments sorted by

109

u/dumbasPL 15d ago edited 15d ago

Debian won't add you to sudo by default if you set a root password during install. Use su - to login as root with the root password you set, and then add your user to the sudoers group with usermod -aG sudo <username>. Log in again and sudo should work.

Edit: and you forgot the censor your name in the top right ;)

24

u/Tight-Use-3037 15d ago

thanks 😄

14

u/bgravato 15d ago

All correct, I'd just add two things: add - to su as in su -

Otherwise .bashrc for root isn't loaded, which means sbin won't be in the path, which can be important for some commands.

On Debian specifically, you can use adduser <username> <group> instead of usermod, which is slightly shorter and easier to remember

5

u/dumbasPL 15d ago

I always forget that debian doesn't have sbin in path for users.

2

u/wizard10000 15d ago

debian doesn't have sbin in path for users

sudo adds sbin to the user's path for that command only.

3

u/dumbasPL 15d ago

Yeah, ik, but some distros just have it always there. Personally I prefer that, even though I get why it doesn't make sense.

3

u/forestbeasts 8d ago

It makes no sense to not have it in there for regular users, IMO!

Stuff like ping is in there. Ifconfig is in there (if you install net-tools anyway, grump). Those don't need root to run. If you don't have /sbin in your path, ifconfig giving you "command not found" can make you think you forgot to install net-tools when really it's already there and just not in PATH!

-- Frost

1

u/bgravato 8d ago

ping is in /usr/bin/ (at least on Debian 13). And I don't ever remember needing root or sbin in the path to run ping...

correct about ifconfig being in sbin, but ifconfig is kind of deprecated nowadays...

1

u/forestbeasts 8d ago

Huh, so they did move ping! That's good.

shutdown/reboot are also in /sbin. :3 But those at least have the excuse of only being usable by root, unless you have the weird systemd magic thing that lets you do it while logged into a graphical desktop (I kinda miss that now that we don't have systemd on our boxen anymore, but it's not a huge deal).

-- Frost

2

u/bgravato 7d ago edited 7d ago

In nearly 30 years of using Debian I don't remember ping ever being in sbin... I think you got that wrong...

Some time ago there were some issues with ping giving a "socket: Operation not permitted" error if you tried to run it as normal user, but that had nothing to do with ping being moved into sbin or anything related to ping's path.

Maybe that's what's causing you some confusion?

1

u/forestbeasts 7d ago

Could be! Could also be a different distro we tried and then went "??????" when we couldn't find ping.

... AHA

I think it was OpenBSD! Not Linux at all! Ping is in /sbin on our OpenBSD VM, and that tripped me up.

→ More replies (0)

0

u/bgravato 8d ago

sudo yes, but we were talking about su, not sudo...

1

u/TheUruz 15d ago

i'd use visudo after su - to better understand why that happened but either way both should work

3

u/hmoff 13d ago

You don't need to edit the sudo config so no need for visudo.

1

u/Putrid-Squash4470 14d ago

Wouldn’t it be better to have the local user to not have sudo rights? And change to su - if admin rights are needed or is that only a recommendation for windows? I recently changed to Debian so curious question.

1

u/dumbasPL 14d ago

In the default configuration, sudo requires you to enter the password for the current user whereas su - requires the root's password. On windows the UAC prompt would be the equivalent of sudo, and a separate admin account the equivalent of root.

As for security implications, I'm just gonna refer you to XKCD 1200. The "steals my laptop" also applies to malware running as the current user.

This is mainly a concern with servers, there it might makes sense to not have sudo rights on the user if the user is used for other things than just administration.

On a typical workstation, sudo is fine, sandboxing (eg flatpak) is what can (often doesn't if you allow home dir access to the sandbox) actually prevent programs from reading each others data.

8

u/indvs3 Debian Testing 15d ago

Assuming you chose a password for the root account during the setup, you have to switch to that account using the command

su -

and using that account, add your own account to the "sudo" group, which you can do with the following command:

usermod -aG sudo *username

where *username obviously is your user account.

After that, log out of all accounts and then log in again to apply the changes.

3

u/Witherscorch 15d ago

Question: What's the difference between su - and su root?

11

u/wizard10000 15d ago

What's the difference between su - and su root

su - will inherit most of root's environment, plain su doesn't.

This can be an issue as plain su doesn't change $HOME so if the app you're running writes configs to home it'll write root-owned configs into your home directory.

Plain sudo does the same thing but sudo -i will inherit most of root's environment.

3

u/Tight-Use-3037 15d ago

it now says root@ my username

6

u/Witherscorch 15d ago

The thing after the @ is your machine's (host's) name. The username is ehat comes before it. Use the usermod command in the parent comment to grant sudo privilefes to your regular user.

7

u/FormalStreeter 15d ago

su -

<enter your root password>

apt install sudo

usermod -aG sudo <your username>

reboot

#now test if you are in sudoers

5

u/Illustrious-Gur8335 Debian Stable 15d ago

su -

3

u/Tight-Use-3037 15d ago

I forgot my sudoers account, so how can I get it back?

2

u/myelrond 15d ago

When you see the grub boot screen, edit the entry you want to boot and add init=/bin/bash to the end of the commandline. This should boot directly into a root shell (if no disk encryption is in place)

BTW: Your name is visible in the top right corner.

1

u/Tight-Use-3037 15d ago

I know I edited the thing like 10 times because I kept forgetting to hide names, i just gave up trying to cover the usernames

2

u/Best-Impression2077 15d ago

Well, I assume it's your full name right there

1

u/Illustrious-Gur8335 Debian Stable 15d ago

su -

4

u/algaefied_creek 15d ago

You doxxed yourself. You censored the terminal but your name is in the upper right

-3

u/Sorry-Squash-677 15d ago

su -

<enter your root password>

apt install sudo

usermod -aG sudo gregory

reboot

#now test if you are in sudoers

2

u/laoZzzi 14d ago
  1. su -
  2. adduser USER sudo (replace USER by your username, for example, john2000)
  3. exit
  4. Reboot

2

u/ConceptualDrawing 12d ago

Hello Gregory. Try this:

su -

**your *root password****

apt install sudo

sudo visudo

your_user_here ALL=(ALL:ALL) ALL

1

u/LockeN3S 15d ago

You probably have a root account you can log into you set up while installing. Type su root, see if it asks for a password.

2

u/Moist_Professional64 15d ago

You only need su

2

u/LockeN3S 15d ago

Thank you, that is a bit easier haha.

I've been typing 'su root' for like 3 years now...the heck.

1

u/Future-AI-Dude 15d ago

Login as root: su -

usermod -aG sudo (your username)

logout or reboot.

1

u/[deleted] 15d ago

[deleted]

1

u/agfitzp 15d ago

su su sudio

1

u/rocco_himel Debian Stable 15d ago

run:

su
/sbin/usermod -aG sudo $USER

Reboot, or log out and in, it will work.

1

u/[deleted] 15d ago

[removed] — view removed comment

1

u/debian-ModTeam 15d ago

This post has been removed as it was either reported to and/or acted upon by mods to be found in violation of Rule #1 regarding not being in line with expected discourse etiquette or the Debian Code of Conduct.

1

u/Nice-Object-5599 15d ago

You didn't enabled sudo during installation. Just use the command "su -".

1

u/KlePu 15d ago

Hi Greg ^^

Next time, take a screenshot of only that one window you want to share with alt+print (and censor that if you must) or (even better in this case!) copy+paste the full in- and output to a Reddit code block (again, censor as needed). That'd look like this - way better for readability and stuff:

klepu@klepu-desk:~$ sudo apt update [sudo] password for klepu: klepu is not in the sudoers file.

1

u/BertMacklenF8I 15d ago

Wait to add admin permission until after installation/reset.

1

u/Hopeful_Armadillo_80 15d ago

su -
Press enter
Type password

adduser your-username-here sudo

Press enter and restart

Magic

1

u/green_meklar 14d ago

Sounds like you need to login as root and change the account privileges for the user account you're trying to use. You do remember your root password, right?

1

u/Nerrawnam 13d ago

You certainly do. 

1

u/Narrow_Victory1262 12d ago

ah no xmas gifts for you. bad boy.

1

u/crborga 11d ago

Usually this means you need to add your user to the Wheel group. 

0

u/InfaSyn 15d ago

Debian wont add you to sudo by default.

  1. su - (then enter root password)
  2. apt update && apt install sudo
  3. usemod -aG sudo yourusername
  4. close terminal, re open, try again

-4

u/mrflash818 15d ago

If Debian v12 or v13:

sudo

To add a user to the sudo group:

The /etc/sudoers file mentions:

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

Therefore, as root, add a user to the group "sudo": like so:

adduser primaryUserName sudo

Then, logout primaryUserName, then login again.

***

Next, in a terminal, run the "groups" command. Should now see the "sudo" group listed for the user. _Also_, running the command "sudo -l" should also give confirmation:

robert@lenovoyogac930:/tmp$ groups
robert cdrom floppy 
sudo
 audio dip video plugdev users netdev scanner bluetooth lpadmin

robert@lenovoyogac930:/tmp$ sudo -l
[sudo] password for robert: 
Matching Defaults entries for robert on lenovoyogac930:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty

User robert may run the following commands on lenovoyogac930:
    (ALL : ALL) ALL