• @courval@lemmy.world
      link
      fedilink
      43 months ago

      How dare you using a 21st century terminal editor that keeps you sane? You’re supposed to learn a whole new set of archaic key bindings! And suffer!

  • Korthrun
    link
    fedilink
    33
    edit-2
    3 months ago

    You mean sudoedit right? Right?

    edit: While there’s a little bit of attention on this I also want to beg you to stop doing sudo su - and start doing sudo -i you know who you are <3

    • @Albbi@lemmy.ca
      link
      fedilink
      123 months ago

      Why memorize a different command? I assume sudoedit just looks up the system’s EDITOR environment variable and uses that. Is there any other benefit?

      • moonlight
        link
        fedilink
        133 months ago

        It doesn’t edit the file directly, it creates a temp file that replaces the file when saving. It means that the editor is run as the user, not as root.

        • @Albbi@lemmy.ca
          link
          fedilink
          33 months ago

          So it opens the file in your editor, since you have read access to it. Then saves your changes to a temp file. Then when you close the editor it does a sudo mv tmpfile readfile?

          I checked this by checking the file ownership when running touch myself. The file is owned by root. sudo nano myself also creates a file owned by root. sudoedit myself bitches at me not to run it in a writable directory.

          sudoedit: myself: editing files in a writable directory is not permitted

          So I ran it in a non-writable directory and the resulting file is still owned by root.

          So is the advantage of sudoedit preventing a possible escalation of privileges situation?

          • Russ
            link
            fedilink
            English
            73 months ago

            For me personally the advantage is that since the editor is opened by your user, it has all of the same config that I’m used to (such as my souped up Neovim config).

            Whereas if you sudo nvim /path/to/file then the editor is opened as root and you don’t have the same configuration.

            • @gi1242@lemmy.world
              link
              fedilink
              33 months ago

              I just make /root/.config/nvim a symlink to ~/.config/nvim and running nvim as root gives me all the same settings I’m used to. (I’d rather not run nvim-qt as root though, so in that case sudoedit is useful.)

      • @morbidcactus@lemmy.ca
        link
        fedilink
        63 months ago

        From the arch wiki

        sudo -e {file}
        

        Set SUDO_EDITOR in your profile to the editor of your choice, benefit is it retains your user profile for that editor, it’s also less to type. For stuff like editing sudoers you’re supposed to use visudo to edit that. Others can probably give better/more thorough reasons to consider it.

      • @sanderium@lemmy.zip
        link
        fedilink
        English
        33 months ago

        Correct but it uses the SUDO_EDITOR environment variable. The benefit is more security while editing system files, it creates a temporary file and when you finish it writes changes to the original. There is more to it but that is all I know, it prevents some exploits.

      • Arthur Besse
        link
        fedilink
        English
        333 months ago

        Why memorize a different command? I assume sudoedit just looks up the system’s EDITOR environment variable and uses that. Is there any other benefit?

        I don’t use it, but, sudoedit is a little more complicated than that.

        details

        from man sudo:

        When invoked as sudoedit, the -e option (described below), is implied.
        
               -e, --edit
                       Edit one or more files instead of running a command.   In  lieu
                       of  a  path name, the string "sudoedit" is used when consulting
                       the security policy.  If the user is authorized by the  policy,
                       the following steps are taken:
        
                       1.   Temporary  copies  are made of the files to be edited with
                            the owner set to the invoking user.
        
                       2.   The editor specified by the policy is run to edit the tem‐
                            porary files.  The sudoers policy  uses  the  SUDO_EDITOR,
                            VISUAL  and  EDITOR environment variables (in that order).
                            If none of SUDO_EDITOR, VISUAL  or  EDITOR  are  set,  the
                            first  program  listed  in the editor sudoers(5) option is
                            used.
        
                       3.   If they have been modified, the temporary files are copied
                            back to their original location and the temporary versions
                            are removed.
        
                       To help prevent the editing of unauthorized files, the  follow‐
                       ing  restrictions are enforced unless explicitly allowed by the
                       security policy:
        
                        •  Symbolic links  may  not  be  edited  (version  1.8.15  and
                           higher).
        
                        •  Symbolic links along the path to be edited are not followed
                           when  the parent directory is writable by the invoking user
                           unless that user is root (version 1.8.16 and higher).
        
                        •  Files located in a directory that is writable by the invok‐
                           ing user may not be edited unless that user is  root  (ver‐
                           sion 1.8.16 and higher).
        
                       Users are never allowed to edit device special files.
        
                       If  the specified file does not exist, it will be created.  Un‐
                       like most commands run by sudo, the editor is run with the  in‐
                       voking  user's  environment  unmodified.  If the temporary file
                       becomes empty after editing, the user will be  prompted  before
                       it is installed.  If, for some reason, sudo is unable to update
                       a file with its edited version, the user will receive a warning
                       and the edited copy will remain in a temporary file.
        

        tldr: it makes a copy of the file-to-be-edited in a temp directory, owned by you, and then runs your $EDITOR as your normal user (so, with your normal editor config)

        note that sudo also includes a similar command which is specifically for editing /etc/sudoers, called visudo 🤪

        • @Flyswat@lemmy.dbzer0.com
          link
          fedilink
          193 months ago

          visudo is a life-saver since it adds some checks to prevent you from breaking your sudo configuration and locking you out of your system.

      • @bitchkat@lemmy.world
        link
        fedilink
        English
        13 months ago

        I believe sudoedit disables being able to spawn commands from the editor. In vi, I think it was :!<command>

  • juipeltje
    link
    fedilink
    63 months ago

    I’m not sure if that’s the joke and it flew over my head but isn’t editing with sudo what you should be doing anyway if it’s a system level file? You shouldn’t change permissions unless the file is actually supposed to be owned by your user.

    • @anton@lemmy.blahaj.zone
      link
      fedilink
      53 months ago

      You are supposed to run sudoedit.
      This command creates a temporary copy, opens it in you editor of choice and overwrites the protected file when the temp file changes.
      That way the editor doesn’t run as root.
      You can see the difference if you run shell command, like whoami, in vim.

      • juipeltje
        link
        fedilink
        13 months ago

        Ah, thanks for clarifying. I hadn’t heard of sudoedit before but that makes a lot of sense.

  • A Wild Mimic appears!
    link
    fedilink
    363 months ago

    as a GUI pleb i just doubleclick the file, which opens kate.

    i edit the file and click save, get asked for my password

    and all is fine.

  • @xia@lemmy.sdf.org
    link
    fedilink
    English
    423 months ago

    Getting flashbacks of me trying to explain to a mac user why using sudo “to make it work” is why he had a growing problem of needing to use sudo… (more and more files owned by root in his home folder).

      • DefederateLemmyMl
        link
        fedilink
        5
        edit-2
        3 months ago

        Personally I am of the nonanoist denomination. I will curse all the demons of hell when on a new system I type vipw or systemctl edit some.service and I am unexpectedly faced with the demon called nano. Words cannot describe how much I loathe this pityful excuse for an editor, this usurper of editing powers, this illegitimate occupier of the editor symlink. How dare you insult me, the omnipotent god called root, by presenting me with a training tool for novices?!

        Fortunately, there are ancient spells that can nullify its powers. ‘I command you: be gone Satan’, I will utter under my breath as I carefully type in the magic incantation to cast it back into the fiery chasm from whence it came:

        apt -y purge nano
        
        disclaimer

        This post may contain up to 50% satire

        • @superkret@feddit.org
          link
          fedilink
          23 months ago

          I exclusively use kate.
          If the server doesn’t have a GUI I install KDE first, so it can be administered properly.

          • DefederateLemmyMl
            link
            fedilink
            23 months ago

            I … have no problems with that. I wouldn’t do what you do, but it’s your server and kate’s a good GUI editor. I use it too when I’m in a GUI workflow. The only issue I have with kate is that it hangs if a mountpoint (NFS or Samba share) is temporarily unavailable.

    • @courval@lemmy.world
      link
      fedilink
      123 months ago

      Hell yeah gotta embrace the pain of using archaic key bindings that you’ll forget until the next time you need to edit a file in the terminal, you must suffer like man. Modem and sane terminal editors are for pussies! If it doesn’t load in 0.01 ms it’s bloated… Whatever you do don’t install anything like micro, just keep suffering!

  • @SleepyPie@lemmy.world
    link
    fedilink
    63 months ago

    If it’s all my system should I really care about chown and chmod? Is the point that automatic processes with user names like www-data have to make edits, and need permission to do so, and that’s it?

    Newish Linux user btw

    • @corsicanguppy@lemmy.ca
      link
      fedilink
      English
      9
      edit-2
      3 months ago

      Short answer: yes.

      One of the tenets of security is that a user or process should have only enough access to do what it needs, and then no more. So your web server, your user account, to your mail server, should have exactly what they need, and usually that’s been intricately planned by the distro.

      If you subvert it you could be writing files as root that www-data now can’t read or write. This kind of error is sometimes obvious and sometimes very subtle.

      Especially if you’re new to this different access model, tread carefully.

      Great news! If you mess it up, many distros are really great at allowing you to compare permissions and reset them. The bad news is that maybe you’re not on one of those. But you could be okay.

    • palordrolap
      link
      fedilink
      93 months ago

      In addition to corsicanguppy’s comment, some — often important — programs actually expect the system to be secured in a particular way and will refuse to function if things don’t look right.

      Now, you’d be right to expect that closing down permissions too tightly could break a system, but people have actually broken their systems by setting permissions too openly on the wrong things as well.

      That said, for general, everyday use, those commands don’t need to be used much, and there might even be a way to do what they do from your chosen GUI. Even so, it nice to know they’re there and what they do for those rare occasions when they might be needed.

      • @SleepyPie@lemmy.world
        link
        fedilink
        13 months ago

        Right, phew, I was kind of worried I should have been editing more of these but I suppose it’s mostly just as I add certain software or features

  • oni ᓚᘏᗢ
    link
    fedilink
    243 months ago

    If your file is not in your home directory, you shouldn’t do chmod or chown in any other file