For example, I can use ssh-id-copy
to get the key and login to the remote server without entering the password.
Is there a similar mechanism to run as root without prompting password?
I don't know. If login with a key is sort of safe, then I argue there should be a mechanism like that for sudo
. NOPASSWD
is not a good solution, however.
Thanks.
It doesn't have key infrastructure for this. You can use sudoer instead.
Create a file in /etc/sudoers.d with
add a line begin with your account
save the file
use it with caution
You say:
But
NOPASSWD
is the solution. Can you clarify your question to explain what you don't like about it?There is a separation of concerns here: authentication is separated from authorization. Once you have proved to the system that you are who you say you are (by logging in),
sudo
is responsible for restricting what you can do.The
sudoers
file syntax is pretty sophisticated (if somewhat arcane). You can restrict individual users (or groups of users) to certain sets of commands, with or without passwords. Would that help alleviate your concerns?