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?).

  • A colleague helped me out. It looks like this is the solution: ssh -i ~/.ssh/id_custom -N -D 8080 username@proxy.server.com – Paul Jacobson Jan 2 '18 at 7:22
  • You may find this answer useful. – Kamil Maciorowski Nov 4 '18 at 21:00

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
| improve this answer | |

For AWS EC2 ssh, I use it like this:

ssh -i mykeypair.pem *user_name*@ec2-*publicDNS.zone*.compute.amazonaws.com
| improve this answer | |
ssh -i yourSSHkeyname username@hostname


| improve this answer | |
  • 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 1 at 13:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.