0

Is there a way to open a local file for editing as a root? I need to make some changes to a config file located at ~/.emacs.d/init.el, but the Emacs tells me that the buffer is read-only.

MadPhysicist
  • 153
  • 6
  • Note that you should not need root permissions to edit a file located under your home directory. Check what you're doing. – Gilles 'SO- stop being evil' Oct 05 '17 at 20:17
  • Not if the owner of that file is root. Then it does not matter in which directory the file is located. – MadPhysicist Oct 05 '17 at 20:23
  • 1
    That's my point: root should not own that file. You should fix that. – Gilles 'SO- stop being evil' Oct 05 '17 at 20:30
  • Also, when I follow the suggestions in that question, I get the following error: File /sudo:[email protected]:/var/root/.emacs.d/init.el no longer exists! Somehow the domain name gets appended and inserted into the command automatically even though I run it as File /sudo::/var/root/.emacs.d/init.el – MadPhysicist Oct 05 '17 at 20:32
  • 1
    Does the file exist? Have you or your administrator configured Tramp? Can you reproduce the problem when you start Emacs with emacs -Q ? – Gilles 'SO- stop being evil' Oct 05 '17 at 20:43
  • 1
    @MadPhysicist: /sudo:: is tramp shorthand for /sudo:root@<host>: – phils Oct 05 '17 at 21:08
  • Is your $HOME set to /var/root? That seems kind of odd. Usually it's /root if you are logged in as root, or /home/MadPhysicist for a normal user called MadPhysicist (for example). – npostavs Oct 06 '17 at 01:13
  • I was able to figure this out after changing the ownership and permissions as @Gilles suggested. For some reason, Emacs created these files as owned by the root. On another note, if I ever wanted to connect to a remote machine and edit some files there, would I do it using the Tramp package? – MadPhysicist Oct 06 '17 at 01:15
  • @MadPhysicist: Yes, you would use Tramp to edit a file on a remote host. e.g. /ssh:<host>:~/.emacs to edit your ~/.emacs file on the <host> machine. See C-h i g (tramp) for full details. If you mean to edit files on a remote machine as the root user on that machine, then see https://stackoverflow.com/q/2177687 – phils Oct 06 '17 at 06:40

0 Answers0