Issue
I have a command I need to run on start up but it requires I enter the password several times and I have no idea how to make this work:
$ systemctl disable systemd-timesyncd && systemctl stop systemd-timesyncd && systemctl enable ntpd && systemctl start ntpd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
Authentication is required to manage system service or unit files.
Authenticating as: benja
Password:
==== AUTHENTICATION COMPLETE ===
Removed /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service.
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ===
Authentication is required to reload the systemd state.
Authenticating as: benja
Password:
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'systemd-timesyncd.service'.
Authenticating as: benja
Password:
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
Authentication is required to manage system service or unit files.
Authenticating as: benja
Password:
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ===
Authentication is required to reload the systemd state.
Authenticating as: benja
Password:
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'ntpd.service'.
Authenticating as: benja
Password:
==== AUTHENTICATION COMPLETE ===
Is this possible? Any suggestions would be greatly appreciated.
Solution
Run it all via sudo in a subshell.
sudo sh -c 'systemctl disable systemd-timesyncd && systemctl stop systemd-timesyncd && systemctl enable ntpd && systemctl start ntpd'
That way sudo
will ask for password only once. Usually sudo
is configured to "remember" the password, so the next time you run sudo
it shouldn't ask for password again, so you also can:
sudo systemctl .. && sudo systemctl ... && sudo etc.
Answered By - KamilCuk Answer Checked By - Gilberto Lyons (WPSolving Admin)