I recently created my keypair via ssh-keygen -t rsa -f ~/.ssh/my_keyname -C pebaken

So I looked into my .ssh folder located in my home user directory and found 2 keys one my_keyname.pub and my_keyname as well as a folder called 'authorized_keys.'

I tried using the public key my_keyname.pub while connecting to my VM I got > Disconnected: No supported authentication methods available (server sent: publickey)

I thought the public key was suppose to be the one you kept and the private key would stay on the server?

I then tried the key without any extension, put it in puttygen and immediately got > Successfully imported foreign key (OpenSSH SSH-2 private key (old PEM format)). To use this key with Putty, you need to use the "Save private" command to save it in Puttys own format.

So am I using the private key after all, because it worked and I successfully connected to my VM.


2 Answers 2


It's in the name.

The private key is the one you keep to yourself, never share this with anyone and ideally keep it encrypted with a passphrase.

The public key can be distributed anywhere, you can publish it in plain text anywhere.

The public key needs to go on the remote server to confirm you have an appropriate key, the private key should never leave your local environment.

The public key can be derived from the private key.

When authenticating your ssh client will offer a public key (which it will derive from the local private key) to the remote server. The server will confirm that public key is able to authenticate to it and offer a challenge that will not be answerable unless you have the private key. Your client answers the challenge with your private key and the remote server lets you login.


The public key is for copying to ~/.ssh/authorized_keys (which is a file, not a directory) on the remote hosts you will be connecting to.

The private key is for connecting with from your local system.


  • Sorry I did mean file, not folder.I'm confused as initially, I believed you needed the public key to access a VM from the outside? The private key would stay on the server.
    – Pebaken
    Commented Mar 10, 2019 at 0:16
  • @Pebaken The public key is used to prove you possess the private key thus confirming you are authorized so long as your public key is listed inside authorized_keys. The client authenticates the server via known_hosts
    – jdwolf
    Commented Mar 10, 2019 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .