LinuxCommandLibrary

rcp

Copy files between machines over a network

TLDR

Copy a file to a remote host

$ rcp [path/to/local_file] [username]@[remote_host]:/[path/to/destination]/
copy

Copy a directory recursively
$ rcp [[-r|--recursive]] [path/to/local_directory] [username]@[remote_host]:/[path/to/destination]/
copy

Preserve the file attributes
$ rcp [[-p|--preserve]] [path/to/local_file] [username]@[remote_host]:/[path/to/destination]/
copy

Force copy without a confirmation
$ rcp [[-f|--from]] [path/to/local_file] [username]@[remote_host]:/[path/to/destination]/
copy

SYNOPSIS

rcp [OPTION]... SOURCE... DESTINATION

Common Usage Patterns:
rcp [-p] [-r] local_file remote_host:remote_path
rcp [-p] [-r] remote_host:remote_path local_file
rcp [-p] [-r] user@remote_host:source_path destination_path
rcp [-p] [-r] source_path user@remote_host:destination_path
rcp [-p] [-r] user1@host1:path1 user2@host2:path2

PARAMETERS

-p
    Preserves the modification times, access times, and modes (permissions) of the source files in the destination.

-r
    Recursively copies directories and their contents. If a source file is a directory, rcp copies the directory and all its files, including subdirectories and their files, to the destination.

DESCRIPTION

rcp (remote copy) is a command-line utility used to transfer files or directories between different machines on a network. It is part of the traditional "r-commands" suite, which includes rsh and rlogin. rcp operates by utilizing rsh as its underlying transport, relying on its authentication mechanisms, such as .rhosts files or host-based authentication. While functional for simple file transfers, rcp is widely considered insecure for modern usage over untrusted networks. This is because it transmits all data, including potential credentials and the file content itself, in plain text, making it highly vulnerable to eavesdropping and man-in-the-middle attacks. For secure and encrypted file transfers, modern alternatives like scp (SSH-based copy) or rsync over SSH are strongly recommended and widely preferred. rcp is primarily found on older systems or within very secure, trusted local networks where its simplicity might still be acceptable for specific legacy tasks. It supports both single file transfers and recursive directory copying.

CAVEATS

rcp is considered a highly insecure command for file transfer over untrusted networks. It transmits all data, including usernames, passwords, and file contents, in plain text, making it vulnerable to eavesdropping, man-in-the-middle attacks, and unauthorized access. Its authentication mechanism, often relying on .rhosts files or /etc/hosts.equiv, is also weak and prone to security breaches. Due to these significant security flaws, its use is strongly discouraged in favor of modern, encrypted alternatives like scp or rsync over SSH.

SECURITY IMPLICATIONS

The most critical aspect of rcp is its lack of encryption. It transmits all data in plain text, making it highly susceptible to interception. It should never be used to transfer sensitive information or over public/untrusted networks.

AUTHENTICATION METHODS

rcp primarily relies on rsh's authentication, which typically uses .rhosts files in user home directories or the /etc/hosts.equiv file. These methods allow passwordless access but are inherently insecure as they trust remote hosts based solely on their IP address or hostname, which can be spoofed.

HISTORY

rcp is one of the original remote commands developed for Berkeley Unix (BSD) in the early 1980s. It was designed to facilitate file transfers between networked Unix systems in a relatively trusted environment. Along with rsh (remote shell) and rlogin (remote login), it formed a core suite of tools for distributed system administration. Its primary advantage was simplicity and ease of use, leveraging host-based authentication. However, with the exponential growth of the internet and increasing awareness of network security in the late 1990s and early 2000s, rcp's fundamental lack of encryption became a critical vulnerability. This led to its gradual deprecation in favor of more secure protocols and commands, particularly scp and rsync which build upon the robust and encrypted SSH protocol. While still available on many legacy systems, its historical context highlights a different era of network security considerations.

SEE ALSO

scp(1), rsync(1), ssh(1), rsh(1), ftp(1)

Copied to clipboard