rcp 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-rcp
핵심 정리
- 로컬과 원격 호스트, 원격 호스트 두 대, 같은 원격 호스트 안에서 파일을 복사합니다. 형식은
rcp 원본 대상이며 원격은호스트:경로나사용자@호스트:경로로 씁니다. -r은 디렉터리를 재귀로,-p는 수정 시각과 모드를 보존해 복사합니다. 원격 경로가 상대 경로면 원격 사용자의 홈 디렉터리부터입니다.- 인증은 원격의
/etc/hosts.equiv나$HOME/.rhosts(권한 600)로 하며, 비밀번호를 묻지 않습니다. Kerberos 5 환경에서는 DCE 자격 증명을 씁니다. - 원격에서 해석할 메타 문자(
*등)는 따옴표나\로 감쌉니다. 파일 이름에:가 있으면 앞에/를 붙이거나 전체 경로를 씁니다. - 평문 통신이라 요즘은
scp(OpenSSH)를 주로 씁니다.scp도-r,-p의 뜻이 같습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (내용이 같고, 6.1 문서에 RBAC 안내가 더해짐) |
| 원문 | IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4 |
| 파일 | /usr/bin/rcp, /etc/hosts.equiv, $HOME/.rhosts, $HOME/.klogin |
| 관련 명령어 | rsh, cp, scp, ftp, umask, krshd |
목적
로컬 호스트와 원격 호스트 사이, 또는 원격 호스트 두 대 사이에 파일을 옮깁니다.
영어 원문
Transfers files between a local and a remote host or between two remote hosts.
구문
rcp [ -p ] [ -F ] [ -k realm ] [ -m ]
{ { User@Host:File | Host:File | File } { User@Host:File | Host:File | File | User@Host:Directory | Host:Directory | Directory }
| [ -r ] { User@Host:Directory | Host:Directory | Directory } { User@Host:Directory | Host:Directory | Directory } }
설명
/usr/bin/rcp 명령은 로컬 호스트와 원격 호스트 사이, 원격 호스트 두 대 사이, 또는 같은 원격 호스트 안의 파일 사이에 파일을 하나 이상 복사합니다.
원격 대상 파일과 디렉터리에는 Host: 매개변수가 있어야 합니다. 원본과 대상 모두 원격 호스트 이름이 없으면 cp 명령과 같습니다. 로컬 파일과 디렉터리 이름에는 Host:가 필요 없습니다.
참고: rcp는 :가 호스트 이름의 끝이라고 봅니다. 파일 이름에 :를 쓰려면 파일 이름 앞에 /를 붙이거나 /부터 시작하는 전체 경로를 씁니다.
Host 앞에 User@가 없으면 원격 호스트에서 로컬 사용자 이름을 쓰고, 있으면 그 이름을 씁니다.
원격 호스트의 파일이나 디렉터리 경로가 없거나 전체 경로가 아니면 원격 사용자 계정의 홈 디렉터리부터로 해석합니다. 또 원격 호스트에서 해석해야 할 메타 문자는 \, ", '로 감싸야 합니다.
파일 권한과 소유권
기본으로 이미 있는 대상 파일의 권한 모드와 소유권은 유지됩니다. 대상 파일이 없으면 보통 원본 파일의 권한 모드를 대상 호스트의 umask로 바꾼 값이 됩니다. -p를 주면 원본 파일의 수정 시각과 모드를 대상 호스트에서 보존합니다.
원격 호스트에 준 사용자 이름이 그 호스트에서 rcp가 쓰는 파일 접근 권한을 정합니다. 또 대상 호스트에 준 사용자 이름이 결과 파일의 소유권과 접근 모드를 정합니다.
표준 인증
다음 가운데 하나를 만족하면 원격 호스트가 접근을 허락합니다.
- 로컬 호스트가 원격 호스트의
/etc/hosts.equiv에 있고, 원격 사용자가 root가 아닙니다. - 원격 사용자 계정의
$HOME/.rhosts에 로컬 호스트와 사용자 이름이 있습니다.
.rhosts의 권한은 무엇이든 정할 수 있지만 600(소유자만 읽기·쓰기)을 권합니다. 이 밖에 원격 사용자 계정에 비밀번호가 정의되어 있지 않아도 접근을 허락합니다. 하지만 보안상 모든 사용자 계정에 비밀번호를 두기를 권합니다.
Kerberos 5 인증
다음을 모두 만족할 때만 원격 호스트가 접근을 허락합니다.
- 로컬 사용자에게 현재 DCE 자격 증명이 있습니다.
- 로컬과 원격 시스템이 Kerberos 5 인증으로 구성되어 있습니다(원격 시스템에 따라 필요 없을 수도 있으며, klogin 포트를 듣는 데몬이 있어야 합니다).
- 원격 시스템이 그 DCE 자격 증명을 원격 계정 접근에 충분하다고 받아들입니다(
kvalid_user함수 참고).
rcp와 이름 있는 파이프
이름 있는 파이프(FIFO, mknod -p로 만든 특수 파일)는 rcp로 복사하지 않습니다. rcp는 복사할 파일에 open 서브루틴을 쓰는데, FIFO 같은 블로킹 장치에서는 이 호출이 멈춰 버립니다.
영어 원문
The /usr/bin/rcp command is used to copy one or more files between the local host and a remote host, between two remote hosts, or between files at the same remote host.
Remote destination files and directories require a specified Host: parameter. If a remote host name is not specified for either the source or the destination, the rcp command is equivalent to the cp command. Local file and directory names do not require a Host: parameter.
Note: The rcp command assumes that a : (colon) terminates a host name. When you want to use a : in a filename, use a / (slash) in front of the filename or use the full path name, including the /.
If a Host is not prefixed by a User@ parameter, the local user name is used at the remote host. If a User@ parameter is entered, that name is used.
If the path for a file or directory on a remote host is not specified or is not fully qualified, the path is interpreted as beginning at the home directory for the remote user account. Additionally, any metacharacters that must be interpreted at a remote host must be quoted using a \ (backslash), a " (double quotation mark), or a ' (single quotation mark).
File Permissions and Ownership
By default, the permissions mode and ownership of an existing destination file are preserved. Usually, if a destination file does not exist, the permissions mode of the destination file is equal to the permissions mode of the source file as modified by the umask command (a special command in the Korn shell) at the destination host. If the rcp command -p flag is set, the modification time and mode of source files are preserved at the destination host.
The user name entered for the remote host determines the file access privileges the rcp command uses at that host. Additionally, the user name given to a destination host determines the ownership and access modes of the resulting destination file or files.
Using Standard Authentication
The remote host allows access if one of the following conditions is satisfied:
The local host is included in the remote host /etc/hosts.equiv file and the remote user is not the root user.
The local host and user name is included in a
$HOME/.rhostsfile on the remote user account.
Although you can set any permissions for the $HOME/.rhosts file, it is recommended that the permissions of the .rhosts file be set to 600 (read and write by owner only).
In addition to the preceding conditions, the rcp command also allows access to the remote host if the remote user account does not have a password defined. However, for security reasons, the use of a password on all user accounts is recommended.
For Kerberos 5 Authentication
The remote host allows access only if all of the following conditions are satisfied:
The local user has current DCE credentials.
The local and remote systems are configured for Kerberos 5 authentication (On some remote systems, this may not be necessary. It is necessary that a daemon is listening to the klogin port).
The remote system accepts the DCE credentials as sufficient for access to the remote account. See the
kvalid_userfunction for additional information.
rcp and Named Pipelines
Do not use the rcp command to copy named pipelines, or FIFOs, (special files created with the mknod -p command). The rcp command uses the open subroutine on the files that it copies, and this subroutine blocks on blocking devices like a FIFO pipe.
Restrictions
SP Kerberos V4 rcp 실행 경로는 원격에서 원격으로의 복사를 지원하지 않습니다. Kerberos가 자격 증명 전달을 지원하지 않기 때문입니다. 이때는 티켓이 없으니 kinit으로 로그인하라는 메시지가 원격 원본 머신에서 나옵니다. Kerberos로 원격 간 복사를 하는 방법은 아래 예 4를 봅니다.
영어 원문
The SP Kerberos V4 rcp execution path does not support remote-to-remote copy as Kerberos does not support forwarding credentials. The message you would receive under these circumstances is the message indicating you do not have tickets and must use kinit to login. The message would be issued from the remote source machine. Please see the example below for using Kerberos to perform a remote-to-remote copy.
플래그
| 플래그 | 설명 |
|---|---|
-p |
root이거나 대상의 소유자일 때만 원본 파일의 수정 시각과 모드를 대상 복사본에 보존합니다. 없으면 대상의 umask가 모드를 바꾸고 수정 시각은 파일을 받은 시각이 됩니다. 이때 적용하는 umask는 umask 명령으로 정한 값이 아니라 해당 데이터베이스에 저장된 값입니다. |
-r |
디렉터리만: 원본 디렉터리의 파일과 하위 디렉터리를 대상 디렉터리로 재귀 복사합니다. |
-F |
자격 증명을 전달하고 원격의 자격 증명도 전달 가능으로 표시합니다. 인증 방법이 Kerberos 5가 아니면 무시하며, 현재 DCE 자격 증명이 전달 가능으로 표시되어 있지 않으면 인증이 실패합니다. |
-k realm |
원격의 영역(realm)이 로컬과 다를 때 지정합니다. 영역은 DCE 셀과 같습니다. Kerberos 5가 아니면 무시합니다. |
-m |
파일 이름의 메타 문자를 지원합니다. |
영어 원문
-p— Preserves the modification times and modes of the source files in the copies sent to the destination only if the user has root authority or is the owner of the destination. Without this flag, the umask command at the destination modifies the mode of the destination file, and the modification time of the destination file is set to the time the file is received. When this flag is not used, the umask being honored is the value stored in the appropriate database. It is not the value that is set by issuing the umask command. The permission and ownership values that result from the umask command do not affect those stored in the database.-r— Recursively copies, for directories only, each file and subdirectory in the source directory into the destination directory.-F— Causes the credentials to be forwarded. In addition, the credentials on the remote system will be marked forwardable (allowing them to be passed to another remote system). This flag will be ignored if Kerberos 5 is not the current authentication method. Authentication will fail if the current DCE credentials are not marked forwardable.-krealm — Allows the user to specify the realm of the remote station if it is different from the local systems realm. For these purposes, a realm is synonymous with a DCE cell. This flag will be ignored if Kerberos 5 is not the current authentication method.-m— Support for metacharacters in filenames.
매개변수
| 매개변수 | 설명 |
|---|---|
Host:File |
원격 대상 파일의 호스트 이름과 파일 이름(:로 구분). |
User@Host:File |
rcp가 옮긴 파일의 소유권을 정할 사용자 이름, 호스트 이름, 원격 대상 파일 이름. 원격 호스트에 준 사용자 이름이 그 호스트에서의 파일 접근 권한을 정합니다. |
File |
로컬 대상 파일 이름. |
Host:Directory |
원격 대상 디렉터리의 호스트 이름과 디렉터리 이름. |
User@Host:Directory |
소유권을 정할 사용자 이름, 호스트 이름, 원격 대상 디렉터리 이름. |
Directory |
로컬 대상 디렉터리 이름. |
참고: rcp는 :를 호스트 이름의 끝으로 보므로, 로컬 파일·디렉터리 이름 안의 : 앞에는 \를 넣어야 합니다.
영어 원문
- Host:File — Specifies the host name (Host) and file name (File) of the remote destination file, separated by a : (colon). Note: Because the rcp command assumes that a : (colon) terminates a host name, you must insert a
\(backslash) before any colons that are embedded in the local file and directory names. - User@Host:File — Specifies the user name (User@) that the rcp command uses to set ownership of the transferred file, the host name (Host), and file name (File) of the remote destination file. The user name entered for the remote host determines the file access privileges the rcp command uses at that host.
- File — Specifies the file name of the local destination file.
- Host:Directory — Specifies the host name (Host) and directory name (Directory) of the remote destination directory. Note: Because the rcp command assumes that a : (colon) terminates a host name, you must insert a
\(backslash) before any colons that are embedded in the local file and directory names. - User@Host:Directory — Specifies the user name (User@) the rcp command uses to set ownership of the transferred file, the host name (Host), and directory name (Directory) of the remote destination directory. The user name entered for the remote host determines the file access privileges the rcp command uses at that host.
- Directory — The directory name of the local destination directory.
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 성공 |
| 0보다 큼 | 오류 |
영어 원문
This command returns the following exit values:
- 0 — Successful completion.
>0— An error occurred.
보안
다음 가운데 하나 이상을 만족할 때만 원격 호스트가 접근을 허락합니다(Kerberos 4 환경).
- 로컬 사용자 ID가 인증 데이터베이스에 주체(principal)로 있고,
kinit으로 인증 티켓을 받았습니다. $HOME/.klogin이 있다면 대상 시스템의 로컬 사용자$HOME에 있어야 하며, 로컬 사용자와 이 계정으로 rsh할 수 있는 사용자·서비스가 나열되어 있어야 합니다. 이 파일은.rhosts와 비슷한 일을 하며, 줄마다principal.instance@realm형식의 주체를 둡니다. 요청한 사용자가.klogin의 주체로 인증되면 접근을 허락합니다..klogin이 없으면 계정 소유자에게 접근을 허락합니다.
보안상 $HOME/.klogin은 원격 사용자가 소유하고 AIX 소유자만 읽고 쓸 수 있어야 합니다(권한 600).
RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 특권과 권한 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다(6.1).
영어 원문
The remote host allows access only if at least one of the following conditions is satisfied:
The local user ID is listed as a principal in the authentication database and had performed a kinit to obtain an authentication ticket.
If a
$HOME/.kloginfile exists, it must be located in the local user's$HOMEdirectory on the target system. The local user must be listed as well as any users or services allowed to rsh into this account. This file performs a similar function to a local .rhosts file. Each line in this file should contain a principal in the form of "principal.instance@realm." If the originating user is authenticated as one of the principals named in .klogin, access is granted to the account. The owner of the account is granted access if there is no .klogin file.
For security reasons, any $HOME/.klogin file must be owned by the remote user and only the AIX owner ID should have read and write access (permissions = 600) to .klogin.
Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.
예제
아래 예에서 로컬 호스트는 원격 호스트의 /etc/hosts.equiv에 들어 있습니다.
| 명령 | 하는 일 |
|---|---|
rcp localfile host2:/home/eng/jane |
로컬 파일 localfile을 원격 호스트 host2로 복사 |
rcp host1:/home/eng/jane/newplan host2:/home/eng/mary |
원격 호스트 host1의 파일을 다른 원격 호스트 host2로 복사 |
rcp -p -r report jane@host2:report |
로컬 디렉터리 트리 report를 host2의 사용자 jane 홈으로 복사하며 모드와 수정 시각을 보존. 원격의 /home/jane/.rhosts에 로컬 호스트와 사용자 이름이 있음 |
- 대상과 서버 모두 Kerberos 4 인증인 SP 시스템에서 root가 원격 간 복사를 합니다. root는 인증 데이터베이스에 있고 로컬 호스트에서
kinit을 했어야 합니다. 로컬 호스트에서 실행해 노드 r05n07의 파일stuff를 노드 r05n05로 복사합니다. root는KRBTKTFILE을 임시 티켓 캐시 파일로 정하고rcmdtgt로 서비스 티켓을 얻으며,rcp는 그 티켓으로 r05n07에서 r05n05로 인증합니다.
/usr/lpp/ssp/rcmd/bin/rsh r05n07 'export KRBTKTFILE=/tmp/rcmdtkt$$; \
/usr/lpp/ssp/rcmd/bin/rcmdtgt; \
/usr/lpp/ssp/rcmd/bin/rcp /tmp/stuff r05n05:/tmp/stuff;'
자주 쓰는 형태:
rcp -p /etc/hosts host2:/etc/hosts # 권한·시각 보존
rcp -rp /data/app admin@host2:/data/ # 디렉터리 통째로
rcp "host2:/var/log/*.log" /tmp/ # 원격에서 와일드카드 해석
scp -rp /data/app admin@host2:/data/ # 같은 일을 ssh로(권장)
영어 원문
In the following examples, the local host is listed in the /etc/hosts.equiv file at the remote host.
- To copy a local file to a remote host, enter:
rcp localfile host2:/home/eng/jane
The file localfile from the local host is copied to the remote host host2.
- To copy a remote file from one remote host to another remote host, enter:
rcp host1:/home/eng/jane/newplan host2:/home/eng/mary
The file /home/eng/jane/newplan is copied from remote host host1 to remote host host2.
- To send the directory subtree from the local host to a remote host and preserve the modification times and modes, enter:
rcp -p -r report jane@host2:report
The directory subtree report is copied from the local host to the home directory of user jane at remote host host2 and all modes and modification times are preserved. The remote file /home/jane/.rhosts includes an entry specifying the local host and user name.
- This example shows how the root user can issue an rcp on a remote host when the authentication is Kerberos 4 on both the target and server. The root user must be in the authentication database and must have already issued kinit on the local host. The command is issued at the local host to copy the file, stuff, from node r05n07 to node r05n05 on an SP.
/usr/lpp/ssp/rcmd/bin/rsh r05n07 ’export KRBTKTFILE=/tmp/rcmdtkt$$; \ /usr/lpp/ssp/rcmd/bin/rcmdtgt; \ /usr/lpp/ssp/rcmd/bin/rcp /tmp/stuff r05n05:/tmp/stuff;’
The root user sets the KRBTKTFILE environment variable to the name of a temporary ticket-cache file and then obtains a service ticket by issuing the rcmdtgt command. The rcp uses the service ticket to authenticate from host r05n07 to host r05n05.
파일
| 파일 | 설명 |
|---|---|
$HOME/.klogin |
로컬 사용자 계정을 쓸 수 있는 원격 사용자 |
/usr/lpp/ssp/rcmd/bin/rcp |
해당하면 SP Kerberos 4 rcp 루틴을 부르는, AIX 보안 /usr/bin/rsh로의 링크 |
영어 원문
$HOME/.klogin— Specifies remote users that can use a local user account.- /usr/lpp/ssp/rcmd/bin/rcp — Link to AIX Secure /usr/bin/rsh that calls the SP Kerberos 4 rcp routine if applicable.
Prerequisite Information
개요는 "IBM Parallel System Support Programs for AIX: Administration Guide"의 보안 장을, 추가 Kerberos 정보는 "IBM Parallel System Support Programs for AIX: Command and Technical Reference"의 "RS/6000 SP Files and Other Technical Information" 절을 봅니다. 원문에 적힌 rs6000.ibm.com 주소는 지금은 쓰이지 않습니다.
영어 원문
Refer to the chapter on security in IBMParallel System Support Programs for AIX: Administration Guide for an overview. You can access this publication at the following Web site: http://www.rs6000.ibm.com/resource/ aix_resource
Refer to the "RS/6000 SP Files and Other Technical Information" section of IBM Parallel System Support Programs for AIX: Command and Technical Reference for additional Kerberos information. You can access this publication at the following Web site: http://www.rs6000.ibm.com/resource/aix_resource
Related information:
- cp command
- kvalid user
- umask command
- krshd command
- Communications and networks
리눅스(GNU)와 다른 점
리눅스에서 rcp는 거의 쓰이지 않고(rsh-client 패키지에만 있음) scp나 rsync -e ssh를 씁니다. scp -rp 원본 사용자@호스트:경로가 rcp -rp와 같고, 인증은 .rhosts 대신 SSH 키(~/.ssh/authorized_keys)로 합니다. 변경분만 옮기려면 rsync -av를 씁니다.