25

Possible Duplicate:
Open file via SSH and Sudo with Emacs

I want to open a file using sudo (say, /etc/hosts) on a remote machine connected by ssh using TRAMP on Emacs.

I tried couple of options, but none of them worked. Can anybody tell me how to go about it?

Thank you

3

2 Answers 2

40

Use following in your .emacs

(set-default 'tramp-default-proxies-alist (quote ((".*" "\\`root\\'" "/ssh:%h:")))) 

Then you can simply type:

C-x C-f /sudo:root@host[#port]:/path/to/file 

It will ask you for your password to access remote shell and then your password again for sudo access.

Sign up to request clarification or add additional context in comments.

6 Comments

Does this login to the remote server as root?
This will login you as a user and run sudo after it. No need to allow ssh for root ;)
I've tried your suggestion and another one (in the duplicate thread mentioned here: stackoverflow.com/questions/2177687/…) but neither of them are working.
It seems you have wrong version of tramp. Use this solution: serverfault.com/questions/123802/…
If you are doing other manipulation of your tramp-default-proxies-alist you might want to use add-to-list instead of set-default.
|
-5

In recent Emacsen and Unixes it's dead simple, just visit a file (C-x C-f) and start the file name with ssh://server:/file.

If you are using Windows, first install Putty and put it in your PATH environment variable. Then when you visit a file use plink://server:/file instead of ssh://server:/file.

EDIT:

This answer is wrong, see the answer below.

3 Comments

Would that not require him to authenticate as root?
ssh will by default use your current username. You can another one by using ssh://username:password@server:/file Entering the password every time gets tedious really fast though, so I suggest setting up public-key authentication (then it's just ssh://username@server:/file).
That gives access to the file as 'username', but the question is now how to save that file if it is owned by root on the remote machine. In Ubuntu installations, for example, it is not possible (by default) to login as root, so you have to access the file as 'username' and then save it as root.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.