The Lazy Admin Blog

Home  /  CentOS • CloudLinux • Security  /  rsync without prompting for password

rsync without prompting for password

October 10, 2022 CentOS, CloudLinux, Security 3 Comments

Rsync is a fast and extraordinarily versatile file-copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. When copying over ssh, rsync will need to authenticate with the receiving side using either password or key authentication. Since it’s a backup tool, and most of the time will be automated, we want to connect with the receiving side without prompting for password – using key authentication.

Step 1 – Generate RSA keys on the source server

ssh-keygen -t rsa
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:

Step 2 – Copy the key to the destination server

ssh-copy-id -i root@target-server-domain-or-ip.com
root@target-server-domain-or-ip.com's password:
Now try logging into the machine, with "ssh 'root@target-server-domain-or-ip.com'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.

If you are using an alternate ssh port (not 22), you can try and use this syntax –

ssh-copy-id "-p 1234" user@target-server-domain-or-ip.com

Replace “1234” with your port
Now test ssh connection from the source server to the destination server –

ssh root@target-server-domain-or-ip.com

When doing the first login you will be notified about “RSA key fingerprint” issue, approve it so he will be added “known_hosts” so the alert won’t show up again.

Tags: rsync, ssh
Previous Article
Next Article

3 Comments

  1. Sven Reply
    January 8, 2024 at 00:19

    your command to copy the public key to the destination server is not correct – you are missing the pub cert after -i

    `ssh-copy-id -i /root/.ssh/id_rsa.pub root@target-server-domain-or-ip.com`

    • TheLazyAdmin Reply
      January 8, 2024 at 15:26

      If you use the command ssh-copy-id -i without specifying anything after the -i, the command will default to using the public key file located at ~/.ssh/id_rsa.pub on your local machine. This file typically contains your default RSA public key, which is the most commonly used key for SSH.

      In other words, if you don’t specify a particular key with -i, ssh-copy-id will attempt to copy your default RSA public key to the ~/.ssh/authorized_keys file of the remote user’s account (in this case, root) on the target server. This is under the assumption that you have already generated an RSA key pair on your local machine and the public key is stored in the standard location.

      If you haven’t generated an RSA key pair, or if the public key is not in the default location, the command will fail and likely display an error message indicating that it can’t find the key file.

  2. Sven Reply
    January 9, 2024 at 01:20

    well – for me it gave an error `/usr/bin/ssh-copy-id: ERROR: failed to open ID file ‘root@192.168.188.188.pub’: No such file` for the command `ssh-copy-id -i root@192.168.188.188`

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Our Blog

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
Emails
ESXI
iSCSI
JetBackup
Linux
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup bash CentOS cloudlinux cPanel CXS Emails freetds google htaccess IMAP InnoDB iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc Oracle php php.ini phpselector rsync ssh ssmtp systemd threads VMFS WHM Wordpress xenserver

Popular Posts

  • Convert JetBackup to cPanel structure October 6, 2022
  • How To Install & Configure a Galera Cluster with MariaDB on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • rsync without prompting for password October 10, 2022

Recent Posts

  • Understanding Why More Threads Can Sometimes Slow Down Performance October 9, 2024
  • Set up a new systemd service May 18, 2024
  • Bash Arrays November 7, 2023
  • rsync without prompting for password October 10, 2022

Recent Comments

  • Sven on rsync without prompting for password
  • TheLazyAdmin on rsync without prompting for password
  • Sven on rsync without prompting for password
  • TheLazyAdmin on Convert JetBackup to cPanel structure
  • Chris on Convert JetBackup to cPanel structure
Privacy Policy • Contact