After read Open file via SSH and Sudo with Emacs then I can sudo edit remote file via
/ssh:username@hostname|sudo:username@hostname:/the-file
but I can't sudo edit local file, Emacs's tramp prompts the password of root@hostname
, because on Ubuntu there no root's password exists (see RootSudo) .
So there is a way to sudo edit local file on Ubuntu?
Summary:
If you want to edit remote/local file with Emacs, @phils has a good answer at
Open file via SSH and Sudo with Emacs;
If you used projectile (version<=0.12.0) and can not sudo edit local file(such as Tamp: sending password
or hang) you can try the following code that fix my issue:
(when (package-installed-p 'projectile)
(defun projectile-project-root ()
"Retrieves the root directory of a project if available.
The current directory is assumed to be the project's root otherwise."
(let ((dir default-directory))
(or (--reduce-from
(or acc
(let* ((cache-key (format "%s-%s" it dir))
(cache-value (gethash cache-key projectile-project-root-cache)))
(if cache-value
(if (eq cache-value 'no-project-root)
nil
cache-value)
(let ((value (funcall it (file-truename dir))))
(puthash cache-key (or value 'no-project-root) projectile-project-root-cache)
value))))
nil
projectile-project-root-files-functions)
(if projectile-require-project-root
(error "You're not in a project")
default-directory))))
(projectile-global-mode))
To see Simple tramp with sudo hangs on 'Sending password' and projectile-global-mode prevents new processes from working over TRAMP #523 for more information.