0

I have a multiple remote servers at Linode and Siteground with ssh connection, passphrase. I was using Windows and Putty to connect to my remote servers but now

I started using Ubuntu 18.04 and I set up openssh-server but now when I'm trying ssh example@example.com I get error Permission Denied(Public key) so I'm guessing

I should copy private keys from my remote server on my local machine but I'm not really sure where to place the keys exactly and how to add them so I can connect?

  • 2
    If you have set up everything correctly, you should definitely not have a single private key on the remote servers. Copy your private keys from the local machine that you used before. You also don't need to set up a local SSH server to connect to remote SSH servers. – Kusalananda Jul 5 '18 at 17:22
  • I don't have private keys at remote server. I am not sure where on my ubuntu local machine I should copy this keys so I can connect to remote. I have .ssh folder and known_hosts file in it and that's all I currently have on my local machine. – chille Jul 5 '18 at 17:27
  • So this question could potentially be about converting a PyTTY key file on Windows to OpenSSH format and copying it to Ubuntu? – Kusalananda Jul 5 '18 at 17:29
0

First don't put your private key on the remote server. Any one compromising this server will have all access that you have.

Now that is out of the way. You have two options.

  1. Create a new private key on your new local machine. Then copy the public key (it comes with the private key, or can be generated from it). to the server. If goes in ~/.ssh/authorized_keys, one per line, so append it, don't overwrite the old one (or use ssh-copy-id).
  2. On the old local machine. Using putty, tell it to export your private-key in open-ssh format, then copy this to the new local machine (running openssh). It goes in directory ~/.ssh/ mine is in file id_rsa.
  • This worked for me. First of all I didn't have a private key on my remote server, I didn't posted question properly - sorry for that. I generated key pairs on my local machine, copied public key and paste it on my remote server on authorized_keys file and then i just added my private key to ssh (ssh-add ~/.ssh/id_rsa) and that's it. Thank you all for your responses. – chille Jul 6 '18 at 6:31
  • Did you know that you can edit the question. And hope to see you around, asking more questions. – ctrl-alt-delor Jul 6 '18 at 8:03
0

I generally use ssh-copy-id to do this.

$ ssh-copy-id
Usage: /usr/bin/ssh-copy-id [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
    -f: force mode -- copy keys without trying to check if they are already installed
    -n: dry run    -- no keys are actually copied
    -h|-?: print this help

Usage

$ ssh-copy-id -i /path/to/id_rsa.pub <user>@<server>

Example

$ ssh-copy-id -i ~/.ssh/id_rsa.pub user1@server.mydom.com
/usr/local/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/user1/.ssh/id_rsa.pub"
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
user1remote@server.mydom.com's password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'user1remote@server.mydom.com'"
and check to make sure that only the key(s) you wanted were added.

NOTE: If you find you need to do this across multiple servers refer to my Q&A titled: How can I propagate my SSH pub key to a list of servers without having to type my password in over and over?.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.