[O/S] Terminal command for root

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
thomastt371
Posts: 8
Joined: 2021-08-04 09:02

[O/S] Terminal command for root

#1 Post by thomastt371 »

I am attempting to update Debian 12 Bookworm for the first time but every time i run the command sudo apt update im aske for my root password which i enter and im getting Michael@debian Michael is not in the sudoers file and i cant find a simple way to fix this..can someone with more experience than me,get me sorted out thanks for reading this post michael

Aki
Global Moderator
Global Moderator
Posts: 3698
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 100 times
Been thanked: 486 times

Re: [O/S] Terminal command for root

#2 Post by Aki »

Hello,

You can use the "su" command; for example, the following command will open a shell for the user root (the root password is required):

Code: Select all

su -l
The shell prompt will change from $ to # (indicating that this is a root shell).

Hope this helps.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

juribel
Posts: 50
Joined: 2024-03-03 06:30
Location: Rheinland, Germany
Been thanked: 12 times

Re: [O/S] Terminal command for root

#3 Post by juribel »

Additionally, after having entered the root shell, you can add your user to the sudoers file with

Code: Select all

usermod -aG sudo <your user name>
After this, you can 'sudo' in your normal user shell.

thomastt371
Posts: 8
Joined: 2021-08-04 09:02

Re: [O/S] Terminal command for root

#4 Post by thomastt371 »

thanks will try that regards michael

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

Re: [O/S] Terminal command for root

#5 Post by None1975 »

thomastt371 wrote: 2024-08-10 08:09 thanks will try that regards michael
Hello.

Don't do this. Just login as root and add one simple command

Code: Select all

adduser yourusername sudo 
where yourusername is your actual name. In Debian this is preferred method to add your user to sudo group.

P.S.

By the way, your can update your system in root shell with simple command

Code: Select all

su -
OS: Debian 12.4 Bookworm / DE: XFCE
Debian Wiki | DontBreakDebian, My config files on github

thomastt371
Posts: 8
Joined: 2021-08-04 09:02

Re: [O/S] Terminal command for root

#6 Post by thomastt371 »

su -1 comes up as an invalid command? michael

juribel
Posts: 50
Joined: 2024-03-03 06:30
Location: Rheinland, Germany
Been thanked: 12 times

Re: [O/S] Terminal command for root

#7 Post by juribel »

Should not be -1 (minus one) but rather -l (minus small letter L)

thomastt371
Posts: 8
Joined: 2021-08-04 09:02

Re: [O/S] Terminal command for root

#8 Post by thomastt371 »

ok tks juribel will try that michael

thomastt371
Posts: 8
Joined: 2021-08-04 09:02

Re: [O/S] Terminal command for root

#9 Post by thomastt371 »

hi juribel ive tried that command su -l which works so i enter root password ok and get a prompt..so enter usermod -ag sudo and my username but then taken to help screen list of su commands? so i am no futher foward and still cant add michael to sdoers list?

User avatar
bbbhltz
Posts: 244
Joined: 2024-01-10 14:53
Location: Normandy
XMMP/Jabber: bbbhltz@mailbox.org
Has thanked: 61 times
Been thanked: 57 times

Re: [O/S] Terminal command for root

#10 Post by bbbhltz »

Just doing this should work.
None1975 wrote: 2024-08-10 10:22 Just login as root and add one simple command

Code: Select all

adduser yourusername sudo 
where yourusername is your actual name. In Debian this is preferred method to add your user to sudo group.
You can see in the official wiki that this is the recommendation.

https://wiki.debian.org/sudo
Add existing user from commandline

To add an existing user with id=foo to group=sudo:

Code: Select all

$ sudo adduser foo sudo
Or course, sudo needs to be installed.
bbbhltz
longtime desktop Linux user; eternal newbie

Aki
Global Moderator
Global Moderator
Posts: 3698
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 100 times
Been thanked: 486 times

Re: [O/S] Terminal command for root

#11 Post by Aki »

Hello,
thomastt371 wrote: 2024-08-10 12:52 su -1 comes up as an invalid command? michael
Yes, because you mistyped "su -1" (minus one) when the command is "su -l" (minus l, l as the first character of the word "login").
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

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

Re: [O/S] Terminal command for root

#12 Post by steve_v »

thomastt371 wrote: 2024-08-10 12:52su -1 comes up as an invalid command
thomastt371 wrote: 2024-08-10 13:12enter usermod -ag sudo and my username but then taken to help screen list of su commands
Enter (or copy-paste) CLI commands exactly as posted, including capitalisation.

Code: Select all

usermod -ag
is not the same as

Code: Select all

usermod -aG
If you have command output or errors to report, don't describe them, post the command you used and the response, verbatim, in code tags. "help screen list of su commands" is too vague to comment on.


There are at least 5 different ways to grant a user sudo permissions:
- Editing the /etc/sudoers file (read the comments in said file), either directly or with 'visudo'.
- Editing the /etc/group file to add your username to the 'sudo' group (which is already in /etc/sudoers).
- Using usermod to add your user to the 'sudo' group ('usermod -aG <group> <user>').
- Using adduser to do the same ('adduser <user> <group>').
- Using gpasswd to do the same ('gpasswd -a <user> <group>').

All of the above options have manual pages, e.g. 'man sudoers', 'man group', 'man usermod' etc.

Note any changes to group membership will require a logout/login to take effect.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

Post Reply