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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












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?










share|improve this question























  • Which version of Ubuntu are you running? And is this the only thing, where this user should have elevated permissions? -- And why do you want this? Maybe it is not as secure as you think.
    – sudodus
    Feb 27 at 16:05







  • 2




    Read man sudoers - it will show you how to allow sudo access only to listed commands. BUT all the editors I use have the capability for a "shell escape" (e.g. vim and :!) that would give access to a root shell. In the security biz, that's Game Over. Also, read man sudoers about sudoedit and the -e option.
    – waltinator
    Feb 27 at 16:07










  • Version: Ubuntu 16.04
    – user786034
    Feb 27 at 16:13














up vote
1
down vote

favorite












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?










share|improve this question























  • Which version of Ubuntu are you running? And is this the only thing, where this user should have elevated permissions? -- And why do you want this? Maybe it is not as secure as you think.
    – sudodus
    Feb 27 at 16:05







  • 2




    Read man sudoers - it will show you how to allow sudo access only to listed commands. BUT all the editors I use have the capability for a "shell escape" (e.g. vim and :!) that would give access to a root shell. In the security biz, that's Game Over. Also, read man sudoers about sudoedit and the -e option.
    – waltinator
    Feb 27 at 16:07










  • Version: Ubuntu 16.04
    – user786034
    Feb 27 at 16:13












up vote
1
down vote

favorite









up vote
1
down vote

favorite











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?










share|improve this question















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?







sudo fstab su etc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 27 at 16:16









pa4080

12.3k52256




12.3k52256










asked Feb 27 at 16:01







user786034


















  • Which version of Ubuntu are you running? And is this the only thing, where this user should have elevated permissions? -- And why do you want this? Maybe it is not as secure as you think.
    – sudodus
    Feb 27 at 16:05







  • 2




    Read man sudoers - it will show you how to allow sudo access only to listed commands. BUT all the editors I use have the capability for a "shell escape" (e.g. vim and :!) that would give access to a root shell. In the security biz, that's Game Over. Also, read man sudoers about sudoedit and the -e option.
    – waltinator
    Feb 27 at 16:07










  • Version: Ubuntu 16.04
    – user786034
    Feb 27 at 16:13
















  • Which version of Ubuntu are you running? And is this the only thing, where this user should have elevated permissions? -- And why do you want this? Maybe it is not as secure as you think.
    – sudodus
    Feb 27 at 16:05







  • 2




    Read man sudoers - it will show you how to allow sudo access only to listed commands. BUT all the editors I use have the capability for a "shell escape" (e.g. vim and :!) that would give access to a root shell. In the security biz, that's Game Over. Also, read man sudoers about sudoedit and the -e option.
    – waltinator
    Feb 27 at 16:07










  • Version: Ubuntu 16.04
    – user786034
    Feb 27 at 16:13















Which version of Ubuntu are you running? And is this the only thing, where this user should have elevated permissions? -- And why do you want this? Maybe it is not as secure as you think.
– sudodus
Feb 27 at 16:05





Which version of Ubuntu are you running? And is this the only thing, where this user should have elevated permissions? -- And why do you want this? Maybe it is not as secure as you think.
– sudodus
Feb 27 at 16:05





2




2




Read man sudoers - it will show you how to allow sudo access only to listed commands. BUT all the editors I use have the capability for a "shell escape" (e.g. vim and :!) that would give access to a root shell. In the security biz, that's Game Over. Also, read man sudoers about sudoedit and the -e option.
– waltinator
Feb 27 at 16:07




Read man sudoers - it will show you how to allow sudo access only to listed commands. BUT all the editors I use have the capability for a "shell escape" (e.g. vim and :!) that would give access to a root shell. In the security biz, that's Game Over. Also, read man sudoers about sudoedit and the -e option.
– waltinator
Feb 27 at 16:07












Version: Ubuntu 16.04
– user786034
Feb 27 at 16:13




Version: Ubuntu 16.04
– user786034
Feb 27 at 16:13










2 Answers
2






active

oldest

votes

















up vote
1
down vote













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).






share|improve this answer




















  • woupsie, too slow;)
    – Simon Van Machin
    Feb 27 at 16:24






  • 1




    Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
    – pa4080
    Feb 27 at 16:27











  • Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
    – user786034
    Feb 27 at 21:43










  • Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
    – Simon Van Machin
    Feb 28 at 7:08











  • Visudo* - typo, on mobile
    – Simon Van Machin
    Feb 28 at 7:16

















up vote
1
down vote













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





echo -e '#!/bin/shnnano /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





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1010332%2fset-up-sudo-so-that-a-particular-common-user-can-edit-etc-fstab%23new-answer', 'question_page');

    );

    Post as a guest





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    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).






    share|improve this answer




















    • woupsie, too slow;)
      – Simon Van Machin
      Feb 27 at 16:24






    • 1




      Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
      – pa4080
      Feb 27 at 16:27











    • Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
      – user786034
      Feb 27 at 21:43










    • Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
      – Simon Van Machin
      Feb 28 at 7:08











    • Visudo* - typo, on mobile
      – Simon Van Machin
      Feb 28 at 7:16














    up vote
    1
    down vote













    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).






    share|improve this answer




















    • woupsie, too slow;)
      – Simon Van Machin
      Feb 27 at 16:24






    • 1




      Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
      – pa4080
      Feb 27 at 16:27











    • Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
      – user786034
      Feb 27 at 21:43










    • Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
      – Simon Van Machin
      Feb 28 at 7:08











    • Visudo* - typo, on mobile
      – Simon Van Machin
      Feb 28 at 7:16












    up vote
    1
    down vote










    up vote
    1
    down vote









    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).






    share|improve this answer












    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).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 27 at 16:24









    Simon Van Machin

    23010




    23010











    • woupsie, too slow;)
      – Simon Van Machin
      Feb 27 at 16:24






    • 1




      Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
      – pa4080
      Feb 27 at 16:27











    • Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
      – user786034
      Feb 27 at 21:43










    • Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
      – Simon Van Machin
      Feb 28 at 7:08











    • Visudo* - typo, on mobile
      – Simon Van Machin
      Feb 28 at 7:16
















    • woupsie, too slow;)
      – Simon Van Machin
      Feb 27 at 16:24






    • 1




      Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
      – pa4080
      Feb 27 at 16:27











    • Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
      – user786034
      Feb 27 at 21:43










    • Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
      – Simon Van Machin
      Feb 28 at 7:08











    • Visudo* - typo, on mobile
      – Simon Van Machin
      Feb 28 at 7:16















    woupsie, too slow;)
    – Simon Van Machin
    Feb 27 at 16:24




    woupsie, too slow;)
    – Simon Van Machin
    Feb 27 at 16:24




    1




    1




    Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
    – pa4080
    Feb 27 at 16:27





    Don't use your favourite editor to edit /etc/sudoers* files, instead that use sudo visudo or sudo visudo -f /etc/sudoers.d/<file-name> . Otherwise any simple typo can lock your system. Reference: askubuntu.com/a/159009/566421
    – pa4080
    Feb 27 at 16:27













    Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
    – user786034
    Feb 27 at 21:43




    Thanks, but it still asks for password after reboot. How can i make this to a specific user and not all of the users in the system? I tried this: username TEST=(TEST:TEST) EDITFSTAB
    – user786034
    Feb 27 at 21:43












    Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
    – Simon Van Machin
    Feb 28 at 7:08





    Add the nopasswd option : "username ALL=NOPASSWD: EDITFSTAB". And as pa4080 mentionned, use visuel
    – Simon Van Machin
    Feb 28 at 7:08













    Visudo* - typo, on mobile
    – Simon Van Machin
    Feb 28 at 7:16




    Visudo* - typo, on mobile
    – Simon Van Machin
    Feb 28 at 7:16












    up vote
    1
    down vote













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





    echo -e '#!/bin/shnnano /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





    share|improve this answer


























      up vote
      1
      down vote













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





      echo -e '#!/bin/shnnano /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





      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









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





        echo -e '#!/bin/shnnano /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





        share|improve this answer














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





        echo -e '#!/bin/shnnano /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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 27 at 16:24

























        answered Feb 27 at 16:15









        pa4080

        12.3k52256




        12.3k52256



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1010332%2fset-up-sudo-so-that-a-particular-common-user-can-edit-etc-fstab%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            pylint3 and pip3 broken

            Missing snmpget and snmpwalk

            How to enroll fingerprints to Ubuntu 17.10 with VFS491