Import SSH keys for remote server

8,234

Solution 1

You can create a ssh keypair in the terminal with the command: ssh-keygen. Then you have to add the public key(.pub).

see man ssh-keygen for more options

Solution 2

Use ssh-copy-id

If your local machine has the ssh-copy-id script installed, you can use it to install your public key to any user that you have login credentials for.

Run the ssh-copy-id script by specifying the user and IP address of the server that you want to install the key on, like this:

ssh-copy-id demo@SERVER_IP_ADDRESS

Solution 3

Finally, this link from debian helped. I created a key first with following command on my local machine :

ssh-keygen -t rsa

Then I copied contents of the public key(/home/username/.ssh/id_rsa.pub) into authorized keys on the server. After that I was able to login without password and solve the problem.

Share:
8,234

Related videos on Youtube

We are Borg
Author by

We are Borg

Working in Pune,India. Open to meet new people, attend conferences, good talks. For followup on any answer or any doubt about posts on SO, email at kernelfreak[at]gmail.com :-)

Updated on September 18, 2022

Comments

  • We are Borg
    We are Borg over 1 year

    I have an Ubuntu 15.10 X64 and I am working on a project for which I am trying out GIT. I have created a repo on one of our remote servers, which is a Debian server, and the repo is accessible via SSH from command line as well as from Intellij. If you need any info, please let me know

    enter image description here

    I am trying to access it via a GIT-UI tool called GitGraken. It is looking for ssh keys for our remote server. How can I get those keys and add it for my user on the system so I can keep an eye on the repository. Any help would be nice.

  • We are Borg
    We are Borg about 8 years
    Shouldn't there already exist a key on the server as it's running an open-ssh server? Shouldn't I add it?
  • We are Borg
    We are Borg about 8 years
    I get an error : /usr/bin/ssh-copy-id: ERROR: No identities found
  • muru
    muru about 8 years
    Isn't this what the other two answers tell you to do?
  • We are Borg
    We are Borg about 8 years
    @muru : DanG's did, but was not detailed enough. But was helpful.. I have accepted it as the answer. Thank you. :-)
  • muru
    muru about 8 years
    Actually copying the key to authorized_keys on the remote server is ssh-copy-id's job.
  • We are Borg
    We are Borg about 8 years
    @muru : It is not working though, that's the first thing I tried after creating the key, dunno why its failing.
  • We are Borg
    We are Borg about 8 years
    @muru I get this error: /usr/bin/ssh-copy-id: ERROR: ssh: Could not resolve hostname /home/akshay/.ssh/id_rsa: Name or service not known
  • DanG
    DanG about 8 years
    @user68186, yes, thx! Ive edited my post. sorry for that issue. .pub --> Public Key. Never share or transfer your private key
  • We are Borg
    We are Borg about 8 years
    @muru : Just installed ssh-copy-id, so don't think its a version issue.
  • Gen
    Gen about 8 years
    Did you add server where that key will be copied? ssh-copy-id -i ~/.ssh/id_rsa.pub root@<ip-or-domain>
  • We are Borg
    We are Borg about 8 years
    @Gen : The -i parameter just specifies the path from which the file is to be copied, I didn't specify that as the remote server user had the file in correct location with correct name...