Download private key manually using ssh

Is it possible to run ssh ignoring the default .ssh and specify a different or more private key?

For instance:

 ssh --private-key other_id_rsa login@host 
+6
source share
2 answers

You can use the -i option.

Source: man ssh

 -i identity_file Selects a file from which the identity (private key) for public key authentication is read. The default is ~/.ssh/identity for protocol version 1, and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and ~/.ssh/id_rsa for protocol version 2. Identity files may also be specified on a per- host basis in the configuration file. It is possible to have multiple -i options (and multiple identities specified in configuration files). ssh will also try to load certificate information from the filename obtained by appending -cert.pub to identity filenames. 
+8
source

You can also add a specific configuration for each host you are accessing, which is almost the same as saving flags available in ssh.

There is a whole world of flags available, and there are some mappings for each specialization provided. In your case, using certain id_rsa files, you can write ~/.ssh/config to your file:

 ... Host host_alias HostName host_name IdentityFile ~/.ssh/id_rsa_you_want ... 

Then you can simply use:

 ssh host_alias 

And id_rsa_you_want will be used - as well as any other configurations that you can apply to the connection. See man ssh_config for a complete list of directives available.

+2
source

All Articles