3

I have two VM machines, and I want them to run a remote command on each other via ssh. I ran these commands on the first machine:

ssh-keygen -t rsa
ssh-copy-id 192.168.254.148

Then I ran this command and it didn't ask for a password:

[root@fazi1 data1]# ssh root@192.168.254.148 df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       7.7G  893M  6.5G  12% /
tmpfs           1.5G   16K  1.5G   1% /dev/shm
/dev/sda1       194M   41M  144M  22% /boot
/dev/sda2        11G  7.7G  2.4G  77% /data1
/dev/sda7       4.5G  539M  3.8G  13% /data2
/dev/sda5       7.7G  1.4G  6.0G  19% /opt

I ran these commands on the second machine:

ssh-keygen -t rsa
ssh-copy-id 192.168.254.150

And when I wanted to check if it is working or not:

[root@fazi2 data1]# ssh root@192.168.254.150 df -h
root@192.168.254.150's password:

Why does it work the way I want on the first machine and act different on the second one?

What should I do? (I ran these commands a few times to make sure I didn't enter an incorrect password.)

  • 1
    It's usually a permissions problem either on the ~/.ssh directory or one of the files. – NickD Jun 30 at 5:00
  • 1
    @NickD do you mean the rwx? or a configuration inside files? – BlackCrystal Jun 30 at 5:11
  • 1
    What user did you create the keys for on the local system and what user ran ssh-copy-id? There is no indication in the question that this was done by the same user that you're trying to connect as (root). Also, you don't need root to run df -h. – Kusalananda Jun 30 at 7:31
  • @Kusalananda i ran all the commands by root. that df -h was just for test that i don't need password.i figured out the problem and solve it. i describe the problem in comment in Ulrich answer. – BlackCrystal Jun 30 at 8:13
  • 2
    @BlackCrystal Clarifications to the question should go into the question, not be left in comments that very few people read. – Kusalananda Jun 30 at 8:57
4

If I remember correctly, if root login is disabled on .150, i.e. you have

PermitRootLogin no

in /etc/sshd/sshd_config, it will reject all the keys, and possibly fall through to password authentication, if that is in principle allowed. (It will also then reject all passwords, even the correct one.)

Running ssh -vvv root@192.168.254.150 false will give you a pretty verbose output of what might go wrong. You'll see lines for your keys in /root/.ssh/id_rsa etc., and you can see if your client is offering them to the server, and if the server likes them. If you're not offering, it's likely a permission problem on the client side, if the server is rejecting them, they're either not in authorized_keys on the remote side (but ssh-copy-id should have given you an error then, or the server doesn't permit root logins.

  • 1
    the PermitRootLogin was yes and -vvv didn't show anything useful. but i finally found the problem. both root passwords on both servers were same. i changed them into something different from each other, it worked. i don't know the reason btw. – BlackCrystal Jun 30 at 7:29

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.