On local machine, I am using the account as test1, and I could use the same account to login remote server. After login as test1 on remote server, I could run sudo su - oracle
to change as oracle user, and then I could all files under account of oracle. But I don't know the password of oracle, I could only change to oracle using sudo su - oracle
. So how to use tramp to edit the file from oracle account on remote server? I read the tramp document, it said we have sudo and su option. I can't simple use su since I don't have the password of oracle. But if using sudo, looks like it doesn't work as the emacs hangs forever.
3 Answers
To ssh in as you, and then run sudo su oracle, and then edit a file, do this:
/ssh:you@remotehost|sudo:oracle@remotehost:/path/to/file
-
1Please make it self standing (i.e. readable without having seen @phils's answer)– StefanCommented Jul 20, 2020 at 19:24
-
-
This appears to work (prompts for password) but after entering the password, autocomplete for the remote path stops working, and it keeps prompting for the password as I type a filepath. If I manually type the whole filepath, it asks if I want to create a directory (which should already exist) so I suspect it's the wrong location somehow. Using Emacs 26.3, spacemacs 0.200.13, tramp 2.3.5.26.3.
password-cache
is set tot
. Any suggestions? Commented Aug 13, 2020 at 14:35 -
1It will prompt for your password to ssh to remotehost. Then it will prompt for your password again to do the sudo su oracle. Depending on what fancy spacemacs autocomplete stuff is going on, you might see some weirdness. I use ido and sometimes when doing complicated tramp stuff like this I have to hit c-f to exit ido and get plain-vanilla emacs behavior. Commented Aug 14, 2020 at 15:43
This is probably a (cross-site) duplicate, as the question has a fairly comprehensive answer on Stack Overflow:
Open file via SSH and Sudo with Emacs
But if using sudo, looks like it doesn't work as the emacs hangs forever.
As you neither show what you've tried, nor provide any details on how far tramp gets (customize the tramp-verbose
option), it's extremely difficult to tell whether there's still a problem, or what it might be.
sudo su - oracle
is not supported by Tramp out-of-the-box. You would need to define an own method in tramp-methods
for this, kind of tricky.
I fear it will be to detailed to fiddle it out here on stackexchange. You might rather ask on the [email protected]
mailing list.
-
2I think they're actually just looking for
/ssh:you@remotehost|sudo:oracle@remotehost:/path/to/file
– philsCommented Oct 31, 2016 at 21:15