• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Run SCP Without Password Prompt Interruption in Linux

by admin

Question: How to run scp command without prompting for any password in Linux?

The password-less operation can be added to cron or schedule in case of reducing manual intervention. The various methods of copy operations include rsync, bacula, and keygen with scp.

1. Generate a key using ssh-keygen for any particular user and server. For example, you can follow this:

# ssh-keygen -t rsa -b 4096 -C "root@localhost"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
33:4c:b1:a1:b0:f7:3a:85:0c:85:b9:6b:eb:c6:69:8b root@localhost
The key's randomart image is:
+--[ RSA 4096]----+
| .o. o |
| o+ . + |
| o.o o |
| .+ = |
| .o S |
| o o o |
| o oo |
| .* . |
| E+o. |
+-----------------+

We can see the generated key as shown below with .pub extention:

# ls -l .ssh/
total 8
-rw-------. 1 root root 3239 Aug 13 13:11 id_rsa
-rw-r--r--. 1 root root 736 Aug 13 13:11 id_rsa.pub

2. Once the the public key is generated, copy the .pub file as authorized_keys under .ssh directory under user home for the user in destination server. Once done, try to do ssh which will connect without password.

# cat .ssh/id_rsa.pub | ssh root@server2 'cat >> .ssh/authorized_keys'
# ssh root@server2

Now you can copy a file using scp as shown below:

# scp test_file.txt root@server2:/tmp/
test_file.txt 100% 20 0.0KB/s 00:00

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to run a cron job on specific days of the week
  2. Permission Table for a File/Directory And File System Users Types
  3. How to recreate LVM device files under /dev directory using vgmknodes
  4. create_ap: command not found
  5. lastcomm: command not found
  6. aspell: command not found
  7. gnome-screenshot: command not found
  8. lrztar Command Examples in Linux
  9. sed: command not found
  10. CentOS / RHEL 7 : Understanding Kexec and Kdump

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright