rsh 명령어 (AIX 5.3·6.1)

핵심 정리

  • 원격 호스트에서 명령 하나를 실행하고 그 표준 출력·오류를 로컬로 받습니다. 명령을 주지 않으면 rlogin으로 원격에 로그인합니다. remsh는 같은 명령입니다.
  • 형식: rsh 호스트 [-l 사용자] [-n] 명령. 예: rsh host2 df, rsh host2 -l jane "ls /tmp".
  • 리디렉션·와일드카드 같은 셸 메타 문자는 따옴표로 감싸면 원격에서, 감싸지 않으면 로컬에서 해석됩니다.
  • 대화형 명령(vi 등)은 실행할 수 없습니다. 루프 안에서 쓰거나 백그라운드로 돌릴 때는 -n(표준 입력을 읽지 않음)을 줍니다.
  • 인증은 원격의 /etc/hosts.equiv(root가 아닐 때)나 $HOME/.rhosts로 하며 비밀번호를 묻지 않습니다. 평문 통신이라 요즘은 ssh 호스트 명령을 주로 씁니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1 구문에서 -a가 빠졌지만 플래그 설명에는 남아 있고, RBAC 안내가 더해짐)
원문 IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4
파일 /usr/bin/rsh, /usr/bin/remsh, /etc/hosts.equiv, $HOME/.rhosts, $HOME/.klogin
관련 명령어 rcp, rlogin, rshd, ssh, dsh

목적

원격 호스트에서 지정한 명령을 실행하거나 원격 호스트에 로그인합니다.

영어 원문

Executes the specified command at the remote host or logs in to the remote host.

구문

text
{ rsh | remsh } RemoteHost [ -n ] [ -l User ] [ -f | -F ] [ -k realm ] [ -S ] [ -u ] [ Command ]

5.3 구문에는 [ -a ]도 있습니다.

설명

/usr/bin/rsh 명령은 RemoteHost로 지정한 원격 호스트에서 Command 매개변수의 명령을 실행합니다. Command가 없으면 그 원격 호스트에 로그인합니다. 로컬 명령줄의 표준 입력을 원격 명령에 보내고, 원격 명령의 표준 출력과 표준 오류를 받습니다.

참고: 원격 명령의 입력은 로컬 명령줄에서 줘야 하므로 rsh로 원격에서 대화형 명령을 실행할 수는 없습니다. 대화형 명령이 필요하면 rlogin을 쓰거나 Command 없이 rsh를 씁니다. Command가 없으면 rsh는 대신 rlogin을 실행합니다.

접근 파일

-l을 주지 않으면 원격 호스트에서 로컬 사용자 이름을 씁니다. -l User를 주면 그 이름을 씁니다.

표준 인증

다음 가운데 하나 이상을 만족할 때만 원격 호스트가 접근을 허락합니다.

  • 로컬 사용자 ID가 root가 아니고, 로컬 호스트 이름이 원격의 /etc/hosts.equiv에 동등 호스트로 있습니다.
  • 로컬 사용자 ID가 root이거나 /etc/hosts.equiv 검사에 실패하면, 원격 사용자 홈 디렉터리의 $HOME/.rhosts에 로컬 호스트와 사용자 이름이 있어야 합니다.

.rhosts의 권한은 무엇이든 정할 수 있지만 600(소유자만 읽기·쓰기)을 권합니다. 이 밖에 원격 사용자 계정에 비밀번호가 정의되어 있지 않아도 접근을 허락합니다. 하지만 보안상 모든 계정에 비밀번호를 두기를 권합니다.

Kerberos 5 인증

다음을 모두 만족할 때만 원격 호스트가 접근을 허락합니다.

  • 로컬 사용자에게 현재 DCE 자격 증명이 있습니다.
  • 로컬과 원격 시스템이 Kerberos 5 인증으로 구성되어 있습니다(원격 시스템에 따라 필요 없을 수도 있으며, klogin 포트를 듣는 데몬이 있어야 합니다).
  • 원격 시스템이 그 DCE 자격 증명을 원격 계정 접근에 충분하다고 받아들입니다(kvalid_user 함수 참고).

원격 명령 실행

원격 명령이 실행 중일 때 인터럽트, 종료, Quit 키를 누르면 해당 신호를 원격 프로세스에 보냅니다. 하지만 Stop 키는 로컬 프로세스만 멈춥니다. 보통 원격 명령이 끝나면 로컬 rsh 프로세스도 끝납니다.

셸 메타 문자를 원격 호스트에서 해석하게 하려면 큰따옴표 안에 넣습니다. 아니면 로컬 셸이 해석합니다.

쓰기 권한이 있는 경로에 호스트 이름으로 rsh의 링크를 만들 수 있습니다.

bash
ln -s /usr/bin/rsh HostName

링크를 만든 뒤에는 HostName Command 형식으로 그 원격 호스트에서 명령을 실행합니다. 예를 들어 원격 호스트 opus에 링크했다면 opus date로 date를 실행합니다. 이때는 -l User를 줄 수 없으므로 로컬 사용자의 계정이 원격 호스트에도 있어야 하며, 없으면 Login incorrect 오류가 납니다. 명령 없이 HostName만 입력하면 rlogin으로 로그인하며, 이때도 원격에 같은 사용자 계정이 있어야 합니다.

영어 원문

The /usr/bin/rsh command executes the command specified by the Command parameter at the remote host specified by the RemoteHost parameter; if the Command parameter is not specified, the rsh command

logs into the remote host specified by the RemoteHost parameter. The rsh command sends standard input from the local command line to the remote command and receives standard output and standard error from the remote command.

Note: Because any input to the remote command must be specified on the local command line, you cannot use the rsh command to execute an interactive command on a remote host. If you need to execute an interactive command on a remote host, use either the rlogin command or the rsh command without specifying the Command parameter. If you do not specify the Command parameter, the rsh command executes the rlogin command instead.

Access Files

If you do not specify the -l flag, the local user name is used at the remote host. If -l User is entered, the specified user name is used at the remote host.

Using Standard Authentication

The remote host allows access only if at least one of the following conditions is satisfied:

  • The local user ID is not the root user, and the name of the local host is listed as an equivalent host in the remote /etc/hosts.equiv file.

  • If either the local user ID is the root user or the check of /etc/hosts.equiv is unsuccessful, the remote user's home directory must contain a $HOME/.rhosts file that lists the local host and user name.

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 rsh command also allows access to the remote host if the remote user account does not have a password defined. However, for security reasons, 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 method is not 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_user function for more information.

Remote Command Execution

When the remote command is run, pressing the Interrupt, Terminate, or Quit key sequences sends the corresponding signal to the remote process. However, pressing the Stop key sequence stops only the local process. Usually, when the remote command terminates, the local rsh process terminates.

To have shell metacharacters interpreted on the remote host, place the metacharacters inside " " (double quotation marks). Otherwise, the metacharacters are interpreted by the local shell.

When using the rsh command, you can create a link to a path (to which you have permission to write), by using a host name that is specified by the HostName parameter as the link name. For example: ln -s /usr/bin/rsh HostName

After the link is established, you can specify the HostName parameter and a command that is specified by the Command parameter from the command line. The rsh command remotely runs the command on the remote host. The syntax is:

HostName Command

For example, if you are linked to remote host opus and want to run the date command, enter: opus date

Because you can not specify the -l User flag, the remote command is successful only if the local user has a user account on the remote host. Otherwise, the rsh command returns a Login incorrect error message. When you specify the HostName parameter without a command, the rsh command calls the rlogin command, which logs you into the remote host. Again, for successful login, the local user must have a user account on the remote host.

플래그

플래그 설명
-a 원격 명령의 표준 오류를 표준 출력과 같게 합니다. 원격 프로세스에 임의 신호를 보내는 기능은 없습니다(6.1 구문에서는 빠짐).
-f 자격 증명을 전달합니다. 인증 방법이 Kerberos 5가 아니면 무시하며, 현재 DCE 자격 증명이 전달 가능으로 표시되어 있지 않으면 인증이 실패합니다.
-F 자격 증명을 전달하고 원격의 자격 증명도 전달 가능으로 표시해 다른 원격 시스템으로 넘길 수 있게 합니다. 조건은 -f와 같습니다.
-k realm 원격의 영역(realm)이 로컬과 다를 때 지정합니다. 영역은 DCE 셀과 같습니다. Kerberos 5가 아니면 무시합니다.
-l User 로컬 사용자 이름 대신 User로 원격 호스트에 로그인합니다. 없으면 로컬과 원격 사용자 이름이 같습니다.
-n 표준 입력을 읽지 않습니다.
-S 보안 옵션. 표준 오류 연결의 원격 IP 주소를 표준 출력 연결과 같게 강제합니다.
-u 표준 AIX 인증만 씁니다.
영어 원문

-a Indicates that the standard error of the remote command is the same as standard output. No provision is made for sending arbitrary signals to the remote process. -f Causes the credentials to be forwarded. This flag is ignored if Kerberos 5 is not the current authentication method. Authentication fails if the current DCE credentials are not marked forwardable. -F Causes the credentials to be forwarded. In addition the credentials on the remote system is marked forwardable (allowing them to be passed to another remote system). This flag is ignored if Kerberos 5 is not the current authentication method. Authentication fails if the current DCE credentials are not marked forwardable. -k realm 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 is ignored if Kerberos 5 is not the current authentication method. -l User Specifies that the rsh command must log in to the remote host as the user specified by the User variable instead of the local user name. If this flag is not specified, the local and remote user names are the same. -n Specifies that the rsh command must not read from standard input.

-S Secure option, force remote IP address of the standard error connection to be the same as the standard output connection.

-u Use standard AIX authentication only.

종료 상태

값 뜻
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/.klogin file exists, it must be in the local user's $HOME directory on the target system. The local user and any user must be listed or the services that are allowed to the rsh command is considered. This file performs a similar function to a local .rhosts file. Each line in this file must contain a principal in the form of principal.instance@realm. If the originating user is authenticated as one

of the principals that are named in the .klogin file, access is granted to the account. The owner of the account is granted access if the .klogin file is not present.

For security reasons, any $HOME/.klogin file must be owned by the remote user and only the AIX owner ID has read and write access (permissions = 600) to the .klogin file.

Attention RBAC users and Trusted AIX users: This command can run 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 that are associated with this command, see the lssecattr command or the getcmdattr subcommand.

예제

아래 예에서 로컬 호스트 host1은 원격 호스트 host2의 /etc/hosts.equiv에 들어 있습니다.

명령 하는 일
rsh host2 df 원격 호스트 host2의 디스크 여유 공간을 로컬에 보여 줌
rsh host2 cat test1 ">>" test2 >>를 따옴표로 감싸 원격에서 해석하게 함. host2에서 test1을 test2 뒤에 붙임
rsh host2 cat test2 >> test3 따옴표가 없어 >>를 로컬이 해석. host2의 test2를 로컬 파일 test3 뒤에 붙임
rsh host2 -l jane cat test4 >> test5 원격에서는 jane의 권한으로 test4를 읽어 로컬 파일 test5 뒤에 붙임
  1. 대상과 서버 모두 Kerberos 4 인증인 SP 시스템에서 root가 원격 간 rcp를 합니다. root는 인증 데이터베이스에 있고 로컬 호스트에서 kinit을 했어야 합니다. 로컬 호스트에서 실행해 노드 r05n07의 파일 stuff를 노드 r05n05로 복사합니다. root는 KRBTKTFILE을 임시 티켓 캐시 파일로 정하고 rcmdtgt로 서비스 티켓을 얻으며, rcp는 그 티켓으로 r05n07에서 r05n05로 인증합니다.
bash
/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;'

자주 쓰는 형태:

bash
for h in node1 node2 node3; do echo "== $h"; rsh $h -n "oslevel -s"; done   # 여러 노드에서 실행
rsh host2 "cd /var/log && ls -lt | head"     # 원격에서 여러 명령
ssh host2 "oslevel -s"                       # 같은 일을 ssh로(권장)
영어 원문

In the following examples, the local host, host1, is listed in the /etc/hosts.equiv file at the remote host, host2.

  1. To check the amount of free disk space on a remote host, enter:
rsh host2 df

The amount of free disk space on host2 is displayed on the local system.

  1. To append a remote file to another file on the remote host, place the >> metacharacters in quotation marks, and enter:
rsh host2 cat test1 ">>" test2

The file test1 is appended to test2 on remote host host2.

  1. To append a remote file at the remote host to a local file, omit the quotation marks, and enter:
rsh host2 cat test2 >> test3

The remote file test2 on host2 is appended to the local file test3.

  1. To append a remote file to a local file and use a remote user's permissions at the remote host, enter:
rsh host2 -l jane cat test4 >> test5

The remote file test4 is appended to the local file test5 at the remote host, with user jane's permissions.

  1. 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/rsh 해당하면 SP Kerberos 4 rsh 루틴을 부르는, AIX 보안 /usr/bin/rsh로의 링크
/usr/lpp/ssp/rcmd/bin/remsh 위와 같음
영어 원문
  • $HOME/.klogin — Specifies remote users that can use a local user account.
  • /usr/lpp/ssp/rcmd/bin/rsh — Link to AIX Secure /usr/bin/rsh that calls the SP Kerberos 4 rsh routine if applicable.
  • /usr/lpp/ssp/rcmd/bin/remsh — Link to AIX Secure /usr/bin/rsh that calls the SP Kerberos 4 rsh 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 IBM Parallel 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 reference:

  • rcp Command

Related information:

  • ftp command
  • Communications and networks

리눅스(GNU)와 다른 점

리눅스에서 rsh는 거의 쓰이지 않고(rsh-client 패키지) ssh 호스트 명령을 씁니다. 따옴표에 따라 원격·로컬 해석이 갈리는 것과 -n(표준 입력 막기)은 ssh도 같습니다. .rhosts 대신 SSH 키(~/.ssh/authorized_keys)로 비밀번호 없이 실행하며, 여러 호스트에 한 번에 실행할 때는 pdsh나 ansible -m shell을 씁니다. 참고로 일부 리눅스에서 rsh는 제한 셸(rbash)이나 ssh로 연결된 별칭일 수 있습니다.