LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 03-08-2017, 12:27 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 11
Post Find a remove an SSH key.


Hello.
When you want SSH to a new server for the first time, SSH show you a key that must be adding to "known_hosts" file but if I want to remove a specific SSH key server then how can I find it?
For example, When I SSH to a server an output like below shown :
Code:
OpenSSH_6.7p1 Debian-5+deb8u3, OpenSSL 1.0.1t  3 May 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to Server [IP] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jason/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u3
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64@openssh.com zlib@openssh.com
debug1: kex: client->server aes128-ctr umac-64@openssh.com zlib@openssh.com
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<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 9a:91:c9:92:05:5d:df:8d:47:b7:fc:4c:17:51:64:1d
debug1: Host 'usa-1.createssh.com' is known and matches the RSA host key.
debug1: Found key in /home/jason/.ssh/known_hosts:33
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available

debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available

debug1: Next authentication method: publickey
debug1: Trying private key: /home/jason/.ssh/id_rsa
debug1: Trying private key: /home/jason/.ssh/id_dsa
debug1: Trying private key: /home/jason/.ssh/id_ecdsa
debug1: Trying private key: /home/jason/.ssh/id_ed25519
debug1: Next authentication method: password
jason@Server's password: 
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (password).
I know the is in line 33 as output said but when I grep "RSA 9a:91:c9:92:05:5d:df:8d:47:b7:fc:4c:17:51:64:1d" then I can't find anything!!!

Thank you.
 
Old 03-08-2017, 12:42 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
Quote:
Originally Posted by hack3rcon View Post
Hello.
When you want SSH to a new server for the first time, SSH show you a key that must be adding to "known_hosts" file but if I want to remove a specific SSH key server then how can I find it?
You'll have to hunt for it by host name or ip number and remove the line from known_hosts. If you don't want to dig through known_hosts with an editor, you can have ssh-keygen remove the key for you:

Code:
ssh-keygen -R 198.51.100.13 -f ~/.ssh/known_hosts
That will remove the key and save a backup copy of it in known_hosts.old. That method works even for lists where the host name or ip number is hashed.
 
4 members found this post helpful.
Old 03-08-2017, 09:40 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938
Quote:
Originally Posted by Turbocapitalist View Post
If you don't want to dig through known_hosts with an editor, you can have ssh-keygen remove the key for you [...]
My, you learn something new every day.
 
Old 03-11-2017, 09:26 AM   #4
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to know/find out/see my ssh host key khaos83 Red Hat 5 01-12-2019 09:05 PM
ssh issue when key and key.pub do not match ilesterg Linux - Security 4 01-30-2017 02:20 PM
SSH skips public key authentication for a key, but works with another key simopal6 Linux - General 1 07-06-2011 08:33 AM
Putty/SSH login failed when using RSA public key: 'Server refused our key' itsecx@gmail.com Linux - Server 10 10-04-2010 01:19 PM
ssh-keygen, how to find the public key belonging to a given private one? ernst Linux - Security 4 02-18-2010 08:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration