6

I need to connect to a SSH proxy server using a ssh keypair that I created specifically for it (not my default id_rsa keypair). I see from the ssh manual that there is a -i option that I can use to specify the new SSH keypair that I want to use.

I'm not sure how to actually invoke the -i option (I can't seem to find examples of the option in use). If this is the standard ssh command, how would I add the option? For the purpose of this question, assume that my new keypair is called id_custom.

ssh -N -D 8080 username@proxy.server.com

I tried adding identityfile=/Users/username/.ssh/id_custom to the end and it didn't work. (I saw this option in ssh - How to specify key in SSHFS?).

fra-san
  • 10,205
  • 2
  • 22
  • 43

3 Answers3

5

Here's the basic command,

ssh -i keyfile target_machine

and more specifically answering your question with the options and keyfile you presented there,

ssh -i /Users/username/.ssh/id_custom -N -D 8080 username@proxy.server.com

which is quite a lot to remember. I recommend using a config file to help you (user-specific one is .ssh/config, system-wide one is /etc/ssh/ssh_config) - man ssh_config for more info. Since you're using a proxy as you mention in your question with -D you can also use the config file to handle those details. Here some config options you could use in your .ssh/config file to allow you to have a simpler ssh command,

Host proxy.server.com
    User username
    IdentityFile ~/.ssh/id_custom
    DynamicForward 8080

then the ssh command becomes easier (I don't know how to set the -N option in .ssh/config so leaving it here),

ssh -N proxy.server.com
Andrew Richards
  • 223
  • 2
  • 5
1

For AWS EC2 ssh, I use it like this:

ssh -i mykeypair.pem *user_name*@ec2-*publicDNS.zone*.compute.amazonaws.com
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
0
ssh -i yourSSHkeyname username@hostname

https://medium.com/secttp/overthewire-bandit-level-13-dd14fd9aa3b2

AdminBee
  • 22,803
  • 2
    Welcome to the site, and thank you for your contribution. Your answer looks quite similar to the other ones, so you may want to edit it to explain how your approach is different from the answers already posted. – AdminBee Jul 01 '20 at 13:35