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 [email protected] 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?

3
  • 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
    Commented Jul 5, 2018 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
    Commented Jul 5, 2018 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
    Commented Jul 5, 2018 at 17:29

2 Answers 2

2

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.
2
  • 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
    Commented Jul 6, 2018 at 6:31
  • Did you know that you can edit the question. And hope to see you around, asking more questions. Commented Jul 6, 2018 at 8:03
0

NOTE: you never want to copy a private key to remote servers, you want to add your key-pair's public key to the remote server so that your private key can be authenticated.


To bootstrap an account on aa remote server 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 [email protected]
/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
[email protected]'s password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh '[email protected]'"
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?.

2
  • 1
    This doesn't add the private key to the remote machine but the public key to the list of accepted keys
    – CpILL
    Commented Jun 26, 2020 at 0:17
  • 1
    @CpILL user's Q meant this, they asked the Q poorly. Added a disclaimer.
    – slm
    Commented Jun 26, 2020 at 22:42

You must log in to answer this question.

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