Use a specific SSH key-pair when connecting via ssh, and temporarily ignore all other keys?

slm

How can I get ssh to temporarily ignore any SSH key-pairs that are present in $HOME/.ssh along with keys that might be loaded in ssh-agent?

NOTE: I don't want to make any changes to my $HOME/.ssh directory by moving SSH key-pair files out of it, nor do I want to edit my $HOME/.ssh/config file, nor remove keys from my keyring (i.e. ssh-agent).

slm

I generally do it like so:

$ ssh -o IdentitiesOnly=yes -F /dev/null -i ~/path/to/some_id_rsa [email protected]

The options are as follows:

  • -o IdentitiesOnly=yes - tells SSH to only use keys that are provided via the CLI and none from the $HOME/.ssh or via ssh-agent
  • -F /dev/null - disables the use of $HOME/.ssh/config
  • -i ~/path/to/some_id_rsa - the key that you explicitly want to use for the connection

Example

$ ssh -v -o IdentitiesOnly=yes -F /dev/null -i ~/my_id_rsa [email protected]
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /dev/null
debug1: Connecting to someserver.mydom.com [10.128.12.124] port 22.
debug1: Connection established.
debug1: identity file /Users/sammingolelli/my_id_rsa type 1
debug1: identity file /Users/sammingolelli/my_id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA f5:60:30:71:8c:a3:da:a3:fe:b1:6d:0b:20:87:23:e1
debug1: Host 'qa03-ost-tesla-h-app01' is known and matches the RSA host key.
debug1: Found key in /Users/sammingolelli/.ssh/known_hosts:103
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/sammingolelli/my_id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to someserver.mydom.com ([10.128.12.124]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Tue Dec  8 19:03:24 2015 from 153.65.219.15
someserver$

Notice in the above output that ssh has only identified the my_id_rsa private key via the CLI and that it uses it to connect to someserver.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

trouble connecting to AWS Lightsail via SSH with keys other than default

Connecting to MySQL via SSH and private key

temporarily disable login using one specific ssh key

Use specific SSH keys for specific servers only

Making use of ssh keys for authentication in other applications?

How to use local Github ssh key when issuing remote git commands on another machine via ssh

ssh key issue connecting to github via remote machine

ssh does not accept renamed key pair via config

What exactly happens when you use SSH without generating a key pair?

After setting up ssh-keys, how can I ssh into the server such that the key-pair will be ignored?

Docker context how to use specific ssh key

Howto force ssh to use a specific private key?

Connecting to MySQL database via SSH

Trouble Connecting to MySQL via SSH

Connecting via SSH to university server

Connecting to github repository via ssh

Cloud Shell loses authentication when connecting via ssh

Permission denied when connecting via ssh (ipv6)

how to access wsl localhost in browser when connecting via SSH?

I am unable to type polish characters when connecting via ssh

Error when connecting to remote virtual machine via ssh

Try various host suffixes when connecting via SSH

~/.ssh/config Host entry not honored when connecting via IP address

Prevent .bash_profile from executing when connecting via SSH

AWS SSH Key Pair Creation

Is an SSH key pair sufficient protection when port forwarding?

Use Pageant with WIndows OpenSSH when connecting over SSH from Powershell

SSH keychain fails to save passphrase when connecting to remote host via SSH as root in macOS

SSH server gives "userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]" when connecting with Putty