Edititing files with Emacs via ssh and sudo Steckerhalter's ƛ
Emacs has pretty impressive remote file editing capabilites through
tramp.el (Transparent Remote Access, Multiple Protocol) – especially via ssh. It is even possible to use git on a remote server through Emacs.
That means you can use Magit,
flycheck etc. just as if you would be working locally, it is just a bit slower of course.
Usually you will be editing files as the same user you login via ssh. But sometimes it gets necessary to change the user for the sake of permissions for example.
To do that with tramp press C-x C-f and enter something like:
If you want to switch to the
www-data user on the host
example.com this would mean:
With this tramp will connect to
example.com via ssh and then switch to the user
sudo. Then your session will run as
www-data user with the appropriate permissions for new files etc.