Is it a bad practice to run a command which requires sudo
in ~/.profile
?
If really want to do that, how can I make the command run at rebooting Ubuntu?
make the command running with
sudo
and under my user account not require password, by editing/etc/sudoers
?provide my password in the command with
sudo
in~/.profile
, byecho <passwd> | sudo -S <mycommand>
?
I haven't verified if the first way works, because I am still learning how to do it.
The second way seems to raise serious security concern, and probably the least way I want to go.
Thanks.
visudo
work from editing the file directly? – Tim Apr 01 '18 at 14:36man visudo
: "visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors.". You definitively do not want/etc/sudoers
get corrupted, recovering from such a situation is a hassle. – nohillside Apr 01 '18 at 14:38~/.profile
is a bash script which contains a command which needsroot
privillege, do I need to add both the script and the command in it to/etc/sudoers
, or just the script? – Tim Apr 01 '18 at 15:03/etc/rc.local
doesn't work (the script doesn't do its job or its work is undone, when booting Ubuntu,). Moreoever, the work done by the script running in an interactive nonlogin shell is undone whenever I suspend and wake up Ubuntu. Specifically, the script containsecho 1600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
. See https://unix.stackexchange.com/questions/419910/ and https://unix.stackexchange.com/q/434740/674 – Tim Apr 01 '18 at 15:43