I'm using the
C-x C-f option to use SSH to edit a file.
The file I'm editing requires my SSH user to use
When I start editing the file it says read-only. How can I remotely edit files requiring
I wrote a command for automating @Manuel Uberti's answer. The second one is the one I'd use. It uses the first one for remote files and uses crux for local files.
(require 'crux) (require 's) (defun my--reopen-remote-file-as-root () "Reopen a remote file as root over tramp." (find-alternate-file (let* ((parts (s-split ":" buffer-file-name)) (hostname (nth 1 parts)) (filepath (car (last parts)))) (concat "/ssh" ":" hostname "|" "sudo" ":" hostname ":" filepath)))) (defun my/reopen-file-as-root () "Reopen a local or remote file as root." (interactive) (if (file-remote-p default-directory) (progn (my--reopen-remote-file-as-root))) (crux-reopen-as-root))