Emacs: Open remote files via ssh
Contents
[This was written in a MSYS2 environment - perhaps this will work in other environments, too.]
Set up ssh-agent (without this, tramp will fail to connect)
-
Add the following to
~/.bashrc
[source]:export SSH_AUTH_SOCK=/tmp/.ssh-socket ssh-add -l > /dev/null if [ $? = 2 ]; then rm -f $SSH_AUTH_SOCK echo Starting new ssh-agent… eval $(ssh-agent -a $SSH_AUTH_SOCK) > /dev/null ssh-add && echo “ssh-agent set up successfully with the following keys:” && ssh-add -l fi
-
With this, after every reboot you will be asked for your key’s passphrase when starting bash the first time.
Open files via sshx
-Prefix
- Start MSYS2.
- MSYS2 starts a bash asks for your key’s passphrase after every reboot.
- Enter your key’s passphrase.
- Start Emacs via
emacs
. - In Emacs open remote file via
C-x C-f /sshx:username@host:path-to-file
. - Note that the well-known
ssh
-prefix (without thex
-suffix) does not work for some reason.
Open files via bookmarks
- To not have to type in those long commands every time you open a remote file,
add a bookmark via
C-x r m
. - Reopen files through bookmarks via
C-x r b
.