1

I recently switched from Windows to Linux, more specifically to Debian 12. I'm struggling a bit because there are a lot of new things, like sudo. Anyway, I'm basically trying to put my regular user as sudo, to facilitate development issues and not have to register as a super user for everything.

I used the command gpasswd -a user sami and in fact it added the user as sudo, if I use groups sami, my user appears as sudo. However, if I try to use su sami and then enter my password correctly, it simply gives no error and nothing happens. If I enter the wrong password it gives me an authentication error. As expected, if I use apt update, without root, it gives a permission denied error. But the strangest thing is that if I type sudo apt install any_package_here or sudo apt update and enter my password, it normally installs the package or update the packages. Can anyone help me?

Example of the Konsole.

sami@sami-debian:~$ su sami
Senha: 
sami@sami-debian:~$ # I entered the correctly pwd
sami@sami-debian:~$ su sami
Senha: 
su: Falha de autenticação
sami@sami-debian:~$ # I entered the wrong pwd and gave me auth failed
sami@sami-debian:~$ apt update
Lendo listas de pacotes... Pronto
E: Não foi possível abrir arquivo de trava /var/lib/apt/lists/lock - open (13: Permissão negada)
E: Impossível criar acesso exclusivo ao directório /var/lib/apt/lists/
W: Problema ao remover o link do ficheiro /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permissão negada)
W: Problema ao remover o link do ficheiro /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permissão negada)
sami@sami-debian:~$ # It's in portuguese, but basically says permission denied for everything
sami@sami-debian:~$ sudo apt install 7zip
Lendo listas de pacotes... Pronto
Construindo árvore de dependências... Pronto
Lendo informação de estado... Pronto        
Os seguintes pacotes foram instalados automaticamente e já não são necessários:
  libdaxctl1 libndctl6 libpmem1 liburing2
Utilize 'sudo apt autoremove' para os remover.
Os NOVOS pacotes a seguir serão instalados:
  7zip
0 pacotes atualizados, 1 pacotes novos instalados, 0 a serem removidos e 0 não atualizados.
É preciso baixar 0 B/976 kB de arquivos.
Depois desta operação, 2.662 kB adicionais de espaço em disco serão usados.
A seleccionar pacote anteriormente não seleccionado 7zip.
(Lendo banco de dados ... 195927 ficheiros e diretórios atualmente instalados.)
A preparar para desempacotar .../7zip_22.01+dfsg-8_amd64.deb ...
A descompactar 7zip (22.01+dfsg-8) ...
Configurando 7zip (22.01+dfsg-8) ...
A processar 'triggers' para man-db (2.11.2-2) ...
sami@sami-debian:~$ # It didn't ask for a password, and I have no idea why, but installed correctly the package
sami@sami-debian:~$ su
Senha:
root@sami-debian:~$ # I entered correctly password for root user and worked as expected

sami@sami-debian:~$ sudo apt update
[sudo] senha para sami: 
Atingido:1 http://deb.debian.org/debian bookworm InRelease
Atingido:2 http://security.debian.org/debian-security bookworm-security InRelease                                 
Atingido:3 http://repo.mysql.com/apt/debian bookworm InRelease                                                    
Atingido:4 http://deb.debian.org/debian bookworm-updates InRelease                                                
Atingido:5 https://packages.microsoft.com/debian/12/prod bookworm InRelease
Atingido:6 https://packages.microsoft.com/repos/code stable InRelease
Lendo listas de pacotes... Pronto
Construindo árvore de dependências... Pronto
Lendo informação de estado... Pronto        
All packages are up to date.
sami@sami-debian:~$ # I entered correctly pwd

I use KDE Plasma

I was hoping that if I entered the terminal, I would be able to execute the commands as if I were a superuser, but it doesn't allow it. Without this, I have to log in as root all the time to do any minimal operation, like changing branches on github. I wanted to make the job easier.

I just did a git clone and when I tried to change branches, it said that I didn't have permission to change something like index.lock. So should I, every time I work in the terminal, use sudo first? I didn't test using sudo git checkout branch. I should it?

New contributor
Sami Daniel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • 1
    Everything is as expected, except that it should not be necessary to become root for "changing branches on github". Please edit your question and copy&paste the commands you use and the error you get.
    – Bodo
    Commented 12 hours ago
  • 2
    "I was hoping that if I entered the terminal, I would be able to execute the commands as if I were a superuser, but it doesn't allow it." - the point of privilege separation is that you do "day to day stuff", like your Git-based development, as a normal unprivileged user, and only jump into privileged mode for system administration operations. You should not expect to run your system as root (privileged user) as the normal situation - this most definitely would not be normal Commented 3 hours ago

1 Answer 1

7

sudo and su work as expected in the examples in your question.

When you are already logged in as user sami, su sami will have no visible effect apart from asking for the password and having to exit to return to the previous shell. The command su sami results in running a shell as user sami. It is not much different from running $SHELL.

You could use su and type root's password to become root if your system is configured to allow this. (not recommended)

Having to type your password on the first invocation of sudo some_command is normal, and it will ask again after some time. (sudo can be configured to allow commands without password.)

It is intentional that you only run those commands as root that really require it, by typing sudo some_command. Running all commands as root is possible but not recommended as it is easy to make mistakes that might result in your system being unusable, e.g. by accidentally removing important system files.


I don't understand why you have to become root for "changing branches on github". This is not normal.

Did you previously run git commands as root instead of as a normal user? Or did you clone your repository to a locatoin outside your home directory?

Please add details to your question if you want to get help regarding this topic.

1
  • Note that su is not "super-user" but just a command to "switch user" (I remember being confused about this back when I was young and dinosaurs roamed the earth). So for example if you want to switch to root, you need sudo su root because your normal user doesn't have enough privilege to switch to root without sudo. As mentioned above, when you run su sami you just switch to being yourself which does nothing except invoke another layer of the shell. Commented 57 mins ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .