0

Using ssh, I want to access

Machine1 --> Machine2

Let's say Machine2 has IP address: 133.165.14.22.

I have copied id_rsa.pub from Machine1 to Machine2 Then in Machine2 I have already did this:

cd ~/.ssh
cat id_rsa.pub >> authorized_keys

But when I tried to do SSH from Machine1

ssh -i /Users/neversaint/.ssh/id_rsa neversaint@133.165.14.22

It still asked for password.

neversaint@133.165.14.22's password:

How can I do it correctly, so that it won't ask for password?

neversaint
  • 103
  • 1
  • 1
  • 5

2 Answers2

2

ssh-copy-id enter password the first time, that will put the right key in the right place.

if you don't have a key, generate a new one ssh-keygen

Jacob Evans
  • 7,886
  • 3
  • 29
  • 57
1

Check the SSH daemon configuration file in Machine2 located at /etc/ssh/sshd_config and check the following fields exist:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

Also check and ensure the authorized_keys file is only readable/writable by you:
chmod 0600 ~/.ssh/authorized_keys

Note: If you make any edits to the conf file, restart the SSH daemon:
sudo service ssh restart

TLin
  • 11
  • 3
  • In addition to this, ensure the private key (id_rsa) and the .ssh directory itself is not group or world writable. – Spooler Feb 03 '17 at 04:22
  • 2
    try `ssh -vvv` and see if it says rejecting.... – Jacob Evans Feb 03 '17 at 04:29
  • @JacobEvans: Here is the ssh -vvv results http://dpaste.com/00M4C8A.txt – neversaint Feb 03 '17 at 04:39
  • 2
    you has no keys..... `ssh-keygen` – Jacob Evans Feb 03 '17 at 04:41
  • @JacobEvans: I don't get it. I already have `/Users/neversaint/.ssh/id_rsa` and `/Users/neversaint/.ssh/id_rsa.pub` – neversaint Feb 03 '17 at 04:43
  • @TLin where should I do ssh restart? Machine1 or Machine2? I tried at Machine2 it gave `ssh: unrecognized service` – neversaint Feb 03 '17 at 04:46
  • 2
    not according to ssh... `debug1: identity file /Users/neversaint/.ssh/id_rsa type -1 debug1: key_load_public: No such file or directory` – Jacob Evans Feb 03 '17 at 04:46
  • @JacobEvans: Why is ssh -vvv cannot identify that? – neversaint Feb 03 '17 at 05:09
  • You only need to restart the ssh daemon in Machine2 if you altered the configuration file. Regarding the ssh verbose results, you forgot the -i when you ran ssh with verbose. Run it again: `ssh -vvv -i /Users/neversaint/.ssh/id_rsa neversaint@133.165.14.22` and update the results. – TLin Feb 03 '17 at 06:10