Sudo may counter intuitivly be the password free option

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-11-21

On EC2 I was having trouble getting a systemctl command to work.

I ran

systemctl status ml-backend.service

and it asked me for a password for the default ubuntu user. However there was no password since ec2 used a key pair and password based login was disabled.

The solution was to run the whole command again with sudo in front:

sudo systemctl status ml-backend.service

This is counter-intuitive, since on my development machine, prepending sudo asks for a password - whereas here it skips it.

What's happening? - The command systemctl was asking for ubuntu's password. But it has no password, therefore it always fails. - When I prepend with sudo I get to skip the usual asking for passwords, since it is using my key instead.