Cuando nos conectamos a un servidor remoto, es habitual introducir nuestra clave pública en el archivo authorized_keys del usuario al que nos vamos a conectar.
athos@ubuntu:~$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDF1IWS2x6J9QMiS97TkLw0IvwbmtM08n+4vLfx6jxcH0gLCJE50juOSeP4fcSF3Y22BmayoLVLWvXo6vBuzoE1zAuc6jfavuJyX0mO7AZtCYj3Ia+FNsoqWP72H829C4LTb0/3lxl8d7j8WcmbELVeDG4DQieOybDYoJn9aBSIuTuaBrLihsZnSnsQ6ci9BecO1VNDs3cPpBCpNEZmUvsFyXA3KuJhlkQaBp8Y4itJQD93427ILLqIFz2RbpcTIV2VruWRWldZuLRJtKoJlJakrJUJDpy/+MqX4D3qMgmUxAlGRT+51OzjceCUHmugKWO3okxLMZM4S0oO7dPsqRYN athos@athos-Z97P-D3
Después de esto, podemos conectarnos al servidor sin tener que introducir la contraseña en el momento de la conexión.
Si una vez conectados, lanzamos algún comando con sudo, veremos que nos pide la contraseña de ese usuario.
athos@ubuntu:~$ sudo ls
[sudo] password for athos:
Si queremos que no nos pida la contraseña, deberemos modificar el archivo /etc/sudoers y añadir NOPASSWD
de la siguiente manera:
# Allow members of group sudo to execute any command
#%sudo ALL=(ALL:ALL) ALL
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
Al añadir NOPASSWD
hacemos que sudo ya no nos pida la contraseña
athos@ubuntu:~$ sudo ls -l /
total 88
drwxr-xr-x 2 root root 4096 Feb 16 18:48 bin
drwxr-xr-x 3 root root 4096 Feb 16 18:49 boot
drwxr-xr-x 18 root root 3880 Feb 22 13:14 dev
drwxr-xr-x 92 root root 4096 Feb 22 13:26 etc
drwxr-xr-x 3 root root 4096 Feb 16 18:45 home
lrwxrwxrwx 1 root root 33 Feb 16 18:49 initrd.img -> boot/initrd.img-4.4.0-173-generic
lrwxrwxrwx 1 root root 33 Feb 16 18:49 initrd.img.old -> boot/initrd.img-4.4.0-142-generic
drwxr-xr-x 23 root root 4096 Feb 16 18:58 lib
drwxr-xr-x 2 root root 4096 Feb 16 18:42 lib64
drwx------ 2 root root 16384 Feb 16 18:42 lost+found
drwxr-xr-x 3 root root 4096 Feb 16 18:42 media
drwxr-xr-x 2 root root 4096 Feb 27 2019 mnt
drwxr-xr-x 2 root root 4096 Feb 27 2019 opt
dr-xr-xr-x 170 root root 0 Feb 22 13:09 proc
drwx------ 3 root root 4096 Feb 16 18:50 root
drwxr-xr-x 24 root root 900 Feb 22 13:23 run
drwxr-xr-x 2 root root 12288 Feb 16 18:58 sbin
drwxr-xr-x 2 root root 4096 Feb 16 18:46 snap
drwxr-xr-x 2 root root 4096 Feb 27 2019 srv
dr-xr-xr-x 13 root root 0 Feb 22 13:08 sys
drwxrwxrwt 8 root root 4096 Feb 22 13:21 tmp
drwxr-xr-x 10 root root 4096 Feb 16 18:42 usr
drwxr-xr-x 13 root root 4096 Feb 16 18:44 var
lrwxrwxrwx 1 root root 30 Feb 16 18:49 vmlinuz -> boot/vmlinuz-4.4.0-173-generic
lrwxrwxrwx 1 root root 30 Feb 16 18:49 vmlinuz.old -> boot/vmlinuz-4.4.0-142-generic