Voglio che l'utente predefinito ubuntusia in grado di eseguire un servizio specifico senza che venga richiesta una password.
In particolare systemctl restart unicorn_my_app.service.
Ho seguito le istruzioni qui per aggiungere l'utente ubuntua un gruppo appena creato LimitedAdmins, che è confermato con:
$ getent group LimitedAdmins
LimitedAdmins:x:1001:ubuntu
Creato un nuovo file, limitedadmins(usando sudo vim) nella /etc/sudoers.ddirectory contenente il seguente testo:
%LimitedAdmins ALL=NOPASSWD: /etc/init.d/unicorn_ofn_america restart, /etc/init.d/unicorn_ofn_america start
Ho anche provato:
%LimitedAdmins ALL=NOPASSWD: /bin/systemctl/unicorn_ofn_america restart, /bin/systemctl/unicorn_ofn_america start
(E /bin/systemd)
Il contenuto di /etc/sudoers/è predefinito come confermato con sudo visudo(o sudo cat /etc/sudoers):
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
(L'hash access #includedirnon è un commento, ma fa parte della sintassi della direttiva #include ).
Tuttavia c'è ancora una richiesta di password dopo l'esecuzione systemctl restart unicorn_my_app.service
Il servizio è presente nella init.ddirectory:
$ ls -l /etc/init.d | grep unicorn
-rwxr--r-- 1 ubuntu ubuntu 1874 Oct 29 06:47 unicorn_my_app
Ho provato a sorridere 755sull'app, ma non pensare che dovrebbe fare la differenza, dal momento che lo ubuntupossiede comunque.
Ho anche provato a riavviare il sistema senza alcuna differenza. Mi manca un passaggio, come un riavvio / ricaricare)? Configurare qualcosa di sbagliato?
Dovrei anche menzionare che ho usato vimper creare il nuovo file all'interno /etc/sudoers.d, in quanto sembra che il visudocomando sia solo per la modifica /etc/sudoers.