49

How can I edit files on my remote host using my local Emacs when I can access the remote host only through SSH with public key authentication? Tramp handles normal password logins pretty well but I can't figure out how to get it work with key pairs. I'm using unix/linux on both ends.

pico
  • 1,349
  • 2
  • 10
  • 15
  • I use TRAMP with public key authentication. Could you please elaborate a bit about what is going wrong (and what version Emacs you're using)? I think TRAMP pretty much just calls out to SSH, so I'd first make sure that "ssh yourname@yourhost" works as expected with public key login. – Phil Aug 30 '09 at 07:54
  • 1
    Thanks, your query directed me to right track and I solved problem (learned to use SSH more properly). However I'd still like to know how to use Tramp when your SSH identity file is in a non-standard location and you would thus need to use the '-i' command line option of SSH. – pico Aug 30 '09 at 09:45
  • 1
    You can add an identity file using ssh-add. – remvee Aug 30 '09 at 12:39

3 Answers3

48

There is no TRAMP equivalent to ssh user@host -i private-key.pem. However, if you run the shell command ssh-add private-key.pem, then ssh (and thus TRAMP) will automatically use private-key.pem for authentication. Simply ssh user@host will work on the shell, and opening the file /user@host:~/filename.txt will work in emacs, without it prompting for a password.

Loren
  • 13,903
  • 8
  • 48
  • 79
  • 9
    If you use a `~/.ssh/config` file to manage your keys, see [@Sebastien](http://stackoverflow.com/a/10738277/881224)'s answer. – yurisich May 23 '14 at 21:56
  • why is it suffixed `.pem`, are not private keys plaintext ascii (eg `id_rsa`)? –  Oct 19 '18 at 11:02
32

I don't get your question as Tramp works perfectly well with public-key authenticated SSH connections. For instance, assuming you have set the following config in ~/.ssh/config:

Host remotehost
    User     mylogin
    Port     22
    Hostname remotehost.fqdn

and assuming that you can run ssh remotehost correctly in a terminal, then you are able to open your remote file using TRAMP C-x C-f /remotehost:path/to/file

Sebastien Varrette
  • 3,876
  • 1
  • 24
  • 21
1

If you are on Windows you can use plink with tramp easily. You have to make sure the plink binary is in your path and have to customize the variable (M-x customize-option) tramp-default-method to plink which combined with pageant would get you what you want.

I let you read the putty home page how to configure pageant to add your key.

There is the method plinkx as well which use the profile name so when you do a :

C-x C-f /putty_profile:

It will get the putty_profile from your putty saved profile name.

If you are using Linux usually modern distros should have the gnome keyring (named as well seahorse) starting X with a global SSH agent. Example on my debian distro :

chmouel@lutece:~$ ps aux|grep ssh-agent
chmouel   2917  0.0  0.0   4904   552 ?        Ss   Aug30   0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /usr/bin/seahorse-agent --execute x-session-manager

if you do a ssh-add (making sure you have identity in your ~/.ssh properly configured) it should request for your password and identify for all your X session.

If it does not happen you probably have a problem somewhere else in your distro.

Chmouel Boudjnah
  • 2,541
  • 3
  • 24
  • 28