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

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

[root@fazi1 data1]# ssh [email protected] 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

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

[root@fazi2 data1]# ssh [email protected] df -h
[email protected]'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, 2019 at 5:00
  • 1
    @NickD do you mean the rwx? or a configuration inside files? Jun 30, 2019 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, 2019 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. Jun 30, 2019 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, 2019 at 8:57

1 Answer 1


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 [email protected] 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. Jun 30, 2019 at 7:29

You must log in to answer this question.

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