I would like to modify a file on a remote server with emacs on a user I can only access through sudo su - username
without a password.
I am currently able to modify files on my personal space on this server using:
C-x C-f /plink:me@server:/path/file
I read there that I could use the following to open a file as the other user:
C-x C-f /plink:me@server|sudo:other@server:/path/file
The problem is that using this syntax, emacs asks me for a password Password for /sudo:other@server:
which I don't have.. giving an empty password does not work, neither does giving my user's password.
Is there a way to configure tramp to connect to this other user as sudo su - other
would do without asking for a password?
PS: I am using emacs 28.1 on Windows 10.
You could specify a new Tramp method, derived from the sudo
method:
(add-to-list 'tramp-methods
`("mysudo"
(tramp-login-program "sudo")
(tramp-login-args (("su") ("-" "%u")))
(tramp-remote-shell ,tramp-default-remote-shell)
(tramp-remote-shell-login ("-l"))
(tramp-remote-shell-args ("-c"))
(tramp-connection-timeout 10)
(tramp-session-timeout 300)))
Then you can open a remote file like
C-x C-f /plink:me@server|mysudo:other@server:/path/file
Disclaimer: it is untested.