is vim safe to use in combination with sudo

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











up vote
1
down vote

favorite












It is not advisable to use sudo with a graphical application like gedit, as described at this link. Accordingly, I have tended to use vim with sudo.



Recently I noticed my ~/.viminfo was owned by root on a fairly fresh install of 16.04 (xenial) so it had me wondering if even vim is considered to be graphical or if there is some other problem with invoking sudo vim. After changing ownership to myself via:



sudo find $HOME -not -user $USER -exec chown $USER:$(id -g) +


and subsequently running sudo vim I was unable to have ~/.viminfo
owned by root, however, I am certain that it recently was owned by root.



Is it unadvisable to invoke sudo vim?










share|improve this question





















  • Some related questions: unix.stackexchange.com/q/134500/103151 - superuser.com/q/1221102/418736 - askubuntu.com/q/211346/367990
    – Byte Commander
    1 hour ago














up vote
1
down vote

favorite












It is not advisable to use sudo with a graphical application like gedit, as described at this link. Accordingly, I have tended to use vim with sudo.



Recently I noticed my ~/.viminfo was owned by root on a fairly fresh install of 16.04 (xenial) so it had me wondering if even vim is considered to be graphical or if there is some other problem with invoking sudo vim. After changing ownership to myself via:



sudo find $HOME -not -user $USER -exec chown $USER:$(id -g) +


and subsequently running sudo vim I was unable to have ~/.viminfo
owned by root, however, I am certain that it recently was owned by root.



Is it unadvisable to invoke sudo vim?










share|improve this question





















  • Some related questions: unix.stackexchange.com/q/134500/103151 - superuser.com/q/1221102/418736 - askubuntu.com/q/211346/367990
    – Byte Commander
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











It is not advisable to use sudo with a graphical application like gedit, as described at this link. Accordingly, I have tended to use vim with sudo.



Recently I noticed my ~/.viminfo was owned by root on a fairly fresh install of 16.04 (xenial) so it had me wondering if even vim is considered to be graphical or if there is some other problem with invoking sudo vim. After changing ownership to myself via:



sudo find $HOME -not -user $USER -exec chown $USER:$(id -g) +


and subsequently running sudo vim I was unable to have ~/.viminfo
owned by root, however, I am certain that it recently was owned by root.



Is it unadvisable to invoke sudo vim?










share|improve this question













It is not advisable to use sudo with a graphical application like gedit, as described at this link. Accordingly, I have tended to use vim with sudo.



Recently I noticed my ~/.viminfo was owned by root on a fairly fresh install of 16.04 (xenial) so it had me wondering if even vim is considered to be graphical or if there is some other problem with invoking sudo vim. After changing ownership to myself via:



sudo find $HOME -not -user $USER -exec chown $USER:$(id -g) +


and subsequently running sudo vim I was unable to have ~/.viminfo
owned by root, however, I am certain that it recently was owned by root.



Is it unadvisable to invoke sudo vim?







sudo vim






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









H2ONaCl

3,047204783




3,047204783











  • Some related questions: unix.stackexchange.com/q/134500/103151 - superuser.com/q/1221102/418736 - askubuntu.com/q/211346/367990
    – Byte Commander
    1 hour ago
















  • Some related questions: unix.stackexchange.com/q/134500/103151 - superuser.com/q/1221102/418736 - askubuntu.com/q/211346/367990
    – Byte Commander
    1 hour ago















Some related questions: unix.stackexchange.com/q/134500/103151 - superuser.com/q/1221102/418736 - askubuntu.com/q/211346/367990
– Byte Commander
1 hour ago




Some related questions: unix.stackexchange.com/q/134500/103151 - superuser.com/q/1221102/418736 - askubuntu.com/q/211346/367990
– Byte Commander
1 hour ago










3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Yes, it is safe.



The problem with sudo gedit is because GUI apps use certain files such as ~/.cache/dconf and after elevated gedit that file becomes root-owned. Well, that particular file contains user-specific settings for GUI apps, including desktop, so if the system can't read those settings - it's bad. IIRC user can't start particular desktop. User's recent files data recently-used.xbel also gets affected.



On the other hand, vim doesn't have that problem. It uses no GUI-related database, and doesn't put anything into recently-used.xbel. It was created for console-only purpose, although gVim also exists. In fact, on some systems vim is your only choice of editor. So it is safer than gedit by virtue of not causing same problems. You're still editing as root in both cases, so you could cause problems with improper editing.



According to this blog :




The first time you use vim, the file '~/.viminfo' is created, and if you use 'sudo vim' the first time you use vim after installing it on a fresh system, the permissions on ~/.viminfo will have the owner set to root instead of the default user.




While author points out it can lead to issue, there's nothing complex - just chown the file back to yourself.



See also:



  • What specific bad things happen when gedit is used with sudo?





share|improve this answer



























    up vote
    1
    down vote













    It's fine to use vi as root. There's going to be times when you need to edit a file that requires sudo or root privileges, like changing your network interfaces file, or maybe editing your sshd config file. Using root for graphical stuff is bad because people would connect to IRC or browse the web as root. If they got a virus while doing so, it would have full root access.






    share|improve this answer



























      up vote
      1
      down vote













      The link is very old (2013). It recommends using gksudo or gksu for graphical applications but both of those are becoming obsolete. Later on the accepted answer also suggests sudo -H though.



      The general consensus in the Ask Ubuntu community recently is to use:



      sudo -H gedit /path/to/filename


      The only problem remains that sudo doesn't have a profile for tab settings, extensions, word wrap, font name, font size, etc. You can inherit these from your user profile though with a wrapper script like this: How can I sync my root gedit with my user gedit's preferences?






      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: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        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%2f1090632%2fis-vim-safe-to-use-in-combination-with-sudo%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        Yes, it is safe.



        The problem with sudo gedit is because GUI apps use certain files such as ~/.cache/dconf and after elevated gedit that file becomes root-owned. Well, that particular file contains user-specific settings for GUI apps, including desktop, so if the system can't read those settings - it's bad. IIRC user can't start particular desktop. User's recent files data recently-used.xbel also gets affected.



        On the other hand, vim doesn't have that problem. It uses no GUI-related database, and doesn't put anything into recently-used.xbel. It was created for console-only purpose, although gVim also exists. In fact, on some systems vim is your only choice of editor. So it is safer than gedit by virtue of not causing same problems. You're still editing as root in both cases, so you could cause problems with improper editing.



        According to this blog :




        The first time you use vim, the file '~/.viminfo' is created, and if you use 'sudo vim' the first time you use vim after installing it on a fresh system, the permissions on ~/.viminfo will have the owner set to root instead of the default user.




        While author points out it can lead to issue, there's nothing complex - just chown the file back to yourself.



        See also:



        • What specific bad things happen when gedit is used with sudo?





        share|improve this answer
























          up vote
          1
          down vote



          accepted










          Yes, it is safe.



          The problem with sudo gedit is because GUI apps use certain files such as ~/.cache/dconf and after elevated gedit that file becomes root-owned. Well, that particular file contains user-specific settings for GUI apps, including desktop, so if the system can't read those settings - it's bad. IIRC user can't start particular desktop. User's recent files data recently-used.xbel also gets affected.



          On the other hand, vim doesn't have that problem. It uses no GUI-related database, and doesn't put anything into recently-used.xbel. It was created for console-only purpose, although gVim also exists. In fact, on some systems vim is your only choice of editor. So it is safer than gedit by virtue of not causing same problems. You're still editing as root in both cases, so you could cause problems with improper editing.



          According to this blog :




          The first time you use vim, the file '~/.viminfo' is created, and if you use 'sudo vim' the first time you use vim after installing it on a fresh system, the permissions on ~/.viminfo will have the owner set to root instead of the default user.




          While author points out it can lead to issue, there's nothing complex - just chown the file back to yourself.



          See also:



          • What specific bad things happen when gedit is used with sudo?





          share|improve this answer






















            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Yes, it is safe.



            The problem with sudo gedit is because GUI apps use certain files such as ~/.cache/dconf and after elevated gedit that file becomes root-owned. Well, that particular file contains user-specific settings for GUI apps, including desktop, so if the system can't read those settings - it's bad. IIRC user can't start particular desktop. User's recent files data recently-used.xbel also gets affected.



            On the other hand, vim doesn't have that problem. It uses no GUI-related database, and doesn't put anything into recently-used.xbel. It was created for console-only purpose, although gVim also exists. In fact, on some systems vim is your only choice of editor. So it is safer than gedit by virtue of not causing same problems. You're still editing as root in both cases, so you could cause problems with improper editing.



            According to this blog :




            The first time you use vim, the file '~/.viminfo' is created, and if you use 'sudo vim' the first time you use vim after installing it on a fresh system, the permissions on ~/.viminfo will have the owner set to root instead of the default user.




            While author points out it can lead to issue, there's nothing complex - just chown the file back to yourself.



            See also:



            • What specific bad things happen when gedit is used with sudo?





            share|improve this answer












            Yes, it is safe.



            The problem with sudo gedit is because GUI apps use certain files such as ~/.cache/dconf and after elevated gedit that file becomes root-owned. Well, that particular file contains user-specific settings for GUI apps, including desktop, so if the system can't read those settings - it's bad. IIRC user can't start particular desktop. User's recent files data recently-used.xbel also gets affected.



            On the other hand, vim doesn't have that problem. It uses no GUI-related database, and doesn't put anything into recently-used.xbel. It was created for console-only purpose, although gVim also exists. In fact, on some systems vim is your only choice of editor. So it is safer than gedit by virtue of not causing same problems. You're still editing as root in both cases, so you could cause problems with improper editing.



            According to this blog :




            The first time you use vim, the file '~/.viminfo' is created, and if you use 'sudo vim' the first time you use vim after installing it on a fresh system, the permissions on ~/.viminfo will have the owner set to root instead of the default user.




            While author points out it can lead to issue, there's nothing complex - just chown the file back to yourself.



            See also:



            • What specific bad things happen when gedit is used with sudo?






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 1 hour ago









            Sergiy Kolodyazhnyy

            67.2k9136299




            67.2k9136299






















                up vote
                1
                down vote













                It's fine to use vi as root. There's going to be times when you need to edit a file that requires sudo or root privileges, like changing your network interfaces file, or maybe editing your sshd config file. Using root for graphical stuff is bad because people would connect to IRC or browse the web as root. If they got a virus while doing so, it would have full root access.






                share|improve this answer
























                  up vote
                  1
                  down vote













                  It's fine to use vi as root. There's going to be times when you need to edit a file that requires sudo or root privileges, like changing your network interfaces file, or maybe editing your sshd config file. Using root for graphical stuff is bad because people would connect to IRC or browse the web as root. If they got a virus while doing so, it would have full root access.






                  share|improve this answer






















                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    It's fine to use vi as root. There's going to be times when you need to edit a file that requires sudo or root privileges, like changing your network interfaces file, or maybe editing your sshd config file. Using root for graphical stuff is bad because people would connect to IRC or browse the web as root. If they got a virus while doing so, it would have full root access.






                    share|improve this answer












                    It's fine to use vi as root. There's going to be times when you need to edit a file that requires sudo or root privileges, like changing your network interfaces file, or maybe editing your sshd config file. Using root for graphical stuff is bad because people would connect to IRC or browse the web as root. If they got a virus while doing so, it would have full root access.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    The Letter M

                    1314




                    1314




















                        up vote
                        1
                        down vote













                        The link is very old (2013). It recommends using gksudo or gksu for graphical applications but both of those are becoming obsolete. Later on the accepted answer also suggests sudo -H though.



                        The general consensus in the Ask Ubuntu community recently is to use:



                        sudo -H gedit /path/to/filename


                        The only problem remains that sudo doesn't have a profile for tab settings, extensions, word wrap, font name, font size, etc. You can inherit these from your user profile though with a wrapper script like this: How can I sync my root gedit with my user gedit's preferences?






                        share|improve this answer
























                          up vote
                          1
                          down vote













                          The link is very old (2013). It recommends using gksudo or gksu for graphical applications but both of those are becoming obsolete. Later on the accepted answer also suggests sudo -H though.



                          The general consensus in the Ask Ubuntu community recently is to use:



                          sudo -H gedit /path/to/filename


                          The only problem remains that sudo doesn't have a profile for tab settings, extensions, word wrap, font name, font size, etc. You can inherit these from your user profile though with a wrapper script like this: How can I sync my root gedit with my user gedit's preferences?






                          share|improve this answer






















                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            The link is very old (2013). It recommends using gksudo or gksu for graphical applications but both of those are becoming obsolete. Later on the accepted answer also suggests sudo -H though.



                            The general consensus in the Ask Ubuntu community recently is to use:



                            sudo -H gedit /path/to/filename


                            The only problem remains that sudo doesn't have a profile for tab settings, extensions, word wrap, font name, font size, etc. You can inherit these from your user profile though with a wrapper script like this: How can I sync my root gedit with my user gedit's preferences?






                            share|improve this answer












                            The link is very old (2013). It recommends using gksudo or gksu for graphical applications but both of those are becoming obsolete. Later on the accepted answer also suggests sudo -H though.



                            The general consensus in the Ask Ubuntu community recently is to use:



                            sudo -H gedit /path/to/filename


                            The only problem remains that sudo doesn't have a profile for tab settings, extensions, word wrap, font name, font size, etc. You can inherit these from your user profile though with a wrapper script like this: How can I sync my root gedit with my user gedit's preferences?







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 20 mins ago









                            WinEunuuchs2Unix

                            38.6k1060144




                            38.6k1060144



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1090632%2fis-vim-safe-to-use-in-combination-with-sudo%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                Confectionery