Question about crontab -e

Priest_Apostate

Active Member
Joined
Nov 7, 2023
Messages
197
Reaction score
47
Credits
2,117
What is the difference between
Code:
crontab -e
and
Code:
sudo crontab -e

Asking because I am in an area with a lousy network connection - one that requires me to restart the NetworkManager.service.
While I know that using sudo has me running a command as root, as the command requires root anyway, is there a difference (and if so, what is the difference between commands inputted via "crontab -e", and "sudo crontab -e")?
 


sudo adds elevated privileges to an instruction , if you are running as admin it is not normally required as you have already got the privileges
 
What is the difference between
Code:
crontab -e
and
Code:
sudo crontab -e

Asking because I am in an area with a lousy network connection - one that requires me to restart the NetworkManager.service.
While I know that using sudo has me running a command as root, as the command requires root anyway, is there a difference (and if so, what is the difference between commands inputted via "crontab -e", and "sudo crontab -e")?
Each user on a system can create a crontab file to run some process at a configured time. If the processes don't need root permissions to run, then creating the file with crontab -e is sufficient. If the process needs root permissions, then it can written by by root with sudo crontab -e. In the latter case, the file won't need to include any sudo command inside it because it will have root permissions by having been written by root which will be reflected in the owner and group output seen when listed in the command: ls -al <crontab_file>.

Root permissions are needed to change system files, like updating databases. If the cron job isn't altering system files or using system commands that need root permissions, then creating the crontab file as user with crontab -e makes sense.
 
It's also possible to create a crontab for root, by logging in as root and running crontab -e. It's not something that is often necessary, but it's sometimes useful.
 


Follow Linux.org


Top