Emacs 23 Tramp: sudo to another user account on a remote machine

It took me a while to figure out the correct incantation to log in to another machine and change user account with sudo: `sudo -u someuser -i`. It’s actually very easy once you know how:


(set-default 'tramp-default-proxies-alist
(quote (("remote.domain" "someuser" "/ssh:%h:"))))

In emacs:

C-x C-f /sudo:someuser@remote.domain:/some/dir

There’s some nice code on http://www.gnu.org/software/tramp/ to display the hostname in the mode-line:

(defconst my-mode-line-buffer-identification
(let ((host-name
(or (file-remote-p default-directory 'host)
(if (string-match "^[^0-9][^.]*\\(\\..*\\)" host-name)
(substring host-name 0 (match-beginning 1))
": %12b"))


'(lambda ()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s