3

I have two computers. From the first I created the account admin1 with password admin1. Then I logged in as a root user and used the ssh-keygen -t rsa command. I did not give a password and hit Enter three times.

Enter image description here

In the next step I typed ssh root@remoteuser's ip. Then I logged out and tried to connect to the second computerm but it asked for the password again...

Next, I used the commands:

#useradd admin1
#passwd admin1
#ssh-keygen -t rsa
#ssh root@remoteuser's ip

Why does it ask for the password again?

  • 1
    U need to copy id ssh-copy-id root@userip – Invoker Jun 1 '15 at 6:44
  • What do you mean? – user117568 Jun 1 '15 at 6:45
  • 1
    Next time restate ur question! And add picture with error please. – Invoker Jun 1 '15 at 6:50
  • Elaborate what you want to do in your question. Does admin1 account have anything to do with your question after all? – yaegashi Jun 1 '15 at 7:17
3
Try this again:

    #useradd admin1
    #passwd admin1
    #ssh-keygen -t rsa
    **#ssh-copy-id root@remoteuserip**
    #exit

then type:

    #ssh root@remoteuser's ip
  • If you wonder what ssh-copy-id does: It appends the public key (id_rsa.pub) to the .ssh/authorized_keys file on the destination side. The public key in .ssh/authorized_keys on the destination needs to match the private key in ssh/id_rsa for remote login to work (and there are some restrictions on access rights of the .ssh directory and the authorized_keys file). If you ever think it should work, but doesn't, this is the place to check. – Guntram Blohm supports Monica Jun 1 '15 at 8:06
11

Generating a key doesn't automatically allow you to log in with it to remote machines. You need to copy the corresponding public key to the machines you want to access, like this:

ssh-copy-id user@remote.machi.ne

This operation will ask you for user's password on remote.machi.ne, but after that you'll be able to ssh with your key:

ssh -l user remote.machi.ne

If you didn't set a password for your key, ssh will no longer ask you to enter one.

On a side note: it looks like you had an old ssh key that you just overwrote.

0

Let's assume your scenario is the following. You have computer1(runs sshd service) and computer2(has the keys) and you need to use the keys to connect from computer2 to computer1.

In computer 2, you will do the ssh-keygen -t rsa and you will generate two keys(one public the one which ends to .pub and the private one). In order to use these keys in your ssh connection from computer2 to computer1 then you have to copy the .pub file to computer1. For the first time you will have to use your password, and after you copy the public key to the remote machine your next sessions will be passwordless(if you leave empty the password in the key generation). Be noted that the user who runs ssh-keygen will have the keys under his home directory in ~/.ssh unless in you change the path and that specific user will have read access to the keys so they can be used.

There are two methods to copy the .pub file to the remote machine, 1st - Automatic) using ssh-copy-id -i ~/id_rsa.pub username@computer1 2nd - Manually) ssh to computer1 and create a directory .ssh in the user's home directory you want to ssh passwordless, and then create a file in .ssh named as authorized_keys and copy-paste the content from computer2.(you can add more keys appending new lines)

Your Answer

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