Skip to content

Instantly share code, notes, and snippets.

@nsleejian
Last active December 15, 2017 01:46
Show Gist options
  • Select an option

  • Save nsleejian/dcb7157c68c96d85618c8da1d9f7cd97 to your computer and use it in GitHub Desktop.

Select an option

Save nsleejian/dcb7157c68c96d85618c8da1d9f7cd97 to your computer and use it in GitHub Desktop.
How do I connect to ssh with a different public key?

=======1=======

Assuming you're on a Unix/Linux environment, you can create or edit the file ~/.ssh/config.

That config file allows you to establish the parameters to use for each host; so, for example:

Host host1
  HostName <hostname_or_ip>
  IdentityFile ~/.ssh/identity_file1

Host Host2
  HostName <hostname_or_ip2>
  User differentusername
  IdentityFile ~/.ssh/identity_file2

Note that host1 and host2 can also be not hostnames, but rather labels to identify a server.

Now you can log onto the to hosts with:

ssh host1
ssh host2

=======2=======

-i <keyfile>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment