Edit file as another user in Emacs

Gergely Polonkai
Nov 10, 2016 :: 08:57

I have recently found this article by Bozhidar Batsov on opening the current file as root. I barely use tramp for sudo access, but when I do, I almost never use root as the target user. So I decided to fix it for my needs.

If the user is not specified, the default is still root. Also, if the current buffer is not visiting a file, I prompt for a filename. As I’m not an ido user, I didn’t bother calling ido-read-file-name; helm overrides read-file-name for me anyway.

Unlike Bozhidar, I barely use this feature, so I didn’t bind this to a key.

comments powered by Disqus

Gergely Polonkai is a systems engineer of a telco company, and also a freelancer self- and software developer.

He is learning about different IT subjects since the late 1990s. These include web development, application building, systems engineering, IT security and many others. He also dug his nose deeply into free software, dealing with different types of Linux and its applications, while also writing and contributing to some open source projects.

On this site he is writing posts about different stuff he faces during work (oh my, yet another IT solutions blog), hoping they can help others with their job, or just to get along with their brand new netbook that shipped with Linux.

“I believe one can only achieve success if they follow their own instincts and listen to, but not bend under others’ opinions. If you change your course just because someone says so, you are following their instincts, not yours.”