Glam Prestige Journal

Bright entertainment trends with youth appeal.

Learning how to use public keys with ssh server

following this tutorial by DigitalOcean

ssh server : kali VM

ssh client : Ubuntu VM

Using an Ubuntu VM I generated a couple of ssh keys but I only need one to use since the others are somewhat duplicates but have a different password

running this command ssh-copy-id kali@192.168.1.10

returns

Number of key(s) added: 4
Now try logging into the machine, with: "ssh 'kali@192.168.1.10'"
and check to make sure that only the key(s) you wanted were added.

How do you remove the keys to be added and stick to the only key generated when running ssh-keygen

I tried to delete the keys by running this command sudo rm -rf /home/kali/.ssh

but every time I try to copy the newly generated key I get 4 keys on the kali VM

1 Answer

It seems to me you are copying 4 keys to your server.

This is taken from the online documentation located at

-i Specifies the identity file that is to be copied (default is ~/.ssh/id_rsa). If this option is not provided, this adds all keys listed by ssh-add -L. Note: it can be multiple keys and adding extra authorized keys can easily happen accidentally! If ssh-add -L returns no keys, then the most recently modified key matching ~/.ssh/id*.pub, excluding those matching ~/.ssh/*-cert.pub, will be used.

Update from the comments:

If you which to remove a certain key just use:

$ rm .ssh/id_target_key*

One of the backup options can be:

$ mv .ssh/id_target_key id_target_key.bak

Remember that there are always 2 keys. One private and one public. The latter has the extension .pub

Where to locate these keyfiles?On the server open /etc/ssh/sshd_config and look for

AuthorizedKeysFile .ssh/authorized_keys

This file can be edited in order to remove your key manually, there might be other users keys installed.

On the client open /etc/ssh/ssh_config and look for an alternative path from there. (Mine is all commented out so ~/.ssh is the default location) ~/ is a relative path which changes per user. Executing the ssh command set with sudo will result in a different path: /root.

8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy