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?

3
  • 3
    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 Sep 19 at 11:26
  • 4
    "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 Sep 19 at 20:32
  • Note that in modern systems, the sudo command usually requires that the user be a member of the group "sudoers".
    – keshlam
    Commented Sep 21 at 3:19

2 Answers 2

14

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. (The effects of su sami are also visible in e.g. $SHLVL and history, but I don't want to go into details because this is not the focus of the question.)

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.

9
  • 4
    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 Sep 19 at 23:19
  • 2
    @WiringHarness that is not correct - you could absolutely run just su (short for su root) without sudo and become root by providing root's password if root had a vaild password set in /etc/shadow, just like with any other user. It's not that "your user doesn't have enough priviliges to switch to root", it's just that many distributions by default disable / disallow logging in as root using a password.
    – kos
    Commented Sep 20 at 0:53
  • 1
    @kos - @WiringHarness is right, though, in that su is simply a switch-user command (technically "substitute user"; TIL). I think that's a big part of OP's confusion. The question's wording makes me think they thought su stood for "super user" (and thus that su sami would open an admin shell for them) because simply su is commonly used to switch to root
    – TylerW
    Commented Sep 20 at 1:17
  • @TylerW Ah yes, that bit is absolutely correct - but the "your normal user doesn't have enough privilege" part is miselading at best - not being able to switch user to root using su has nothing to do with any "privilege", so I thought I'd clear up their confusion about that (in case they didn't just poorly worded their comment, and other user's confusion in reading their comment regardless)
    – kos
    Commented Sep 20 at 1:36
  • 1
    @WiringHarness It's well past time for the sudo su meme to die once and for all. sudo already does all the necessary manipulations, and with better access control, so su doesn't add anything. sudo -u someuser somecmd and su someuser -c somecmd are basically the same (give or take the extra shell quoting needed to make the latter work sanely, and whose password you need to type). Use sudo -u otheruser -i for interactive use, or sudo -u otheruser somecmd to run a specific command. You can omit -u root, since that's the default. Commented Sep 20 at 5:43
1

I found the 'error'. I created the directory through command line as root. I used the ls -l to see the permissions and as expected my common user, sami, only had execute and read, but no write rights. Makes sense since I created as root, I can't do that type of operations, like git checkout, at the files. I'm sorry for wasting your time. Linux is very new for me.

1
  • 3
    This is what I suspected. You can use chown as root to fix the ownership. Unfortunately you did not add these details to the question.
    – Bodo
    Commented Sep 20 at 8:50

You must log in to answer this question.

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