Star Hype News.

Premium celebrity moments with standout appeal.

news

Set up sudo so that a particular common user can edit /etc/fstab

By Sophia Bowman

How can I set up sudo so that a particular common user can edit /etc/fstab? I've thought to edit /etc/sudoers.d file to do this, but how do we edit /etc/fstab in this file?

3

2 Answers

Adding a line in sudoers.d with you favorite editing software in a cmd alias should do the trick :

Cmnd_Alias EDITFSTAB = /etc/bin/vim /etc/fstab
username ALL = (user) EDITFSTAB

Be careful, there is a huge risk of escape privilege, maybe you should write a basic shell script to restrict/control fstab modifications WITHOUT using editor (ie "for that modification, press 1" and echo-ing right in fstab).

7

Create simple script, called editfstab and located in /usr/local/bin (to be accessible as shell command), and make it executable:

echo -e '#!/bin/sh\nnano /etc/fstab' | sudo tee /usr/local/bin/editfstab && sudo chmod +x /usr/local/bin/editfstab

Run the command sudo visudo -f /etc/sudoers.d/editfstab and add the following rule as content of the newly created file:

ALL ALL=NOPASSWD: /usr/local/bin/editfstab

At this point, each system user will be able to edit /etc/fstab, without password, by the command:

sudo editfstab

You can extend the functionality of /usr/local/bin/editfstab by adding a feature to make backup copy before edit:

#!/bin/sh
cp /etc/fstab /etc/fstab.bak
nano /etc/fstab
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy