ssh remote command with trusted by ssh-keygen Hint!

[local ~]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx root@local

The key's randomart image is:

+---[RSA 2048]----+

|   ... .         |

+----[SHA256]-----+

 

[local ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@remote -p22

root@remote's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '22' 'root@remote'"

and check to make sure that only the key(s) you wanted were added.

 

[local ~]# ssh -p22 root@remote "df -h"

 

[local ~]# ssh -p22 root@ remote << EOF

df -h

EOF