Remote shell daemon

Note: You must be root to start this daemon.


rshd [-aln]

Runs on:



Request the address for the hostname, and verify whether the address and name correspond.
Unless the user is the superuser, prevent any validation based on the user's .rhosts file.
Disable transport-level keepalive messages.


The rshd daemon is the server for the rcmd() function and, consequently, for the rsh utility. The daemon provides remote execution facilities with authentication based on privileged port numbers from trusted hosts.

The rshd daemon is started when inetd receives a service request at the port indicated by the cmd entry (inetd listens for service requests specified in the inetd.conf file at a port defined in the services file). Note that the descriptions in the default inetd.conf file are commented out; uncomment the ones that you want to use. The following protocol is initiated:

  1. The server checks the client's source port. If the port isn't in the range 512-1023, the server aborts the connection.
  2. The server reads characters from the socket up to a NULL (\0) byte. The resultant string is interpreted as an ASCII number, base 10.
  3. If the number received in step 2 is nonzero, it's interpreted as the port number of a secondary stream to be used for standard error. A second connection is then created to the specified port on the client's machine. The source port of this second connection is also in the range 512-1023.
  4. The server checks the client's source address and requests the corresponding hostname (see gethostbyaddr(), the /etc/hosts file, and named). If the hostname cannot be determined, the dot-notation representation of the host address is used. If the hostname is in the same domain as the server (according to the last two components of the domain name), or if the -a option is given, the address for the hostname is requested, and the server verifies whether the address and name correspond. If address verification fails, the connection is aborted with the message, "Host address mismatch."
  5. A NULL-terminated username of at most 16 characters is retrieved on the initial socket. This username is interpreted as the user ID on the client's machine.
  6. A NULL-terminated username of at most 16 characters is retrieved on the initial socket. This username is interpreted as a user ID to use on the server's machine.
  7. A NULL-terminated command to be passed to a shell is retrieved on the initial socket. The length of the command is limited by the upper boundary on the size of the system's argument list.
  8. The rshd server then validates the user by means of ruserok(), which uses the file /etc/hosts.equiv and the file .rhosts found in the user's home directory. The -l option prevents ruserok() from doing any validation based on the user's .rhosts file unless the user is the superuser.
  9. A NULL byte is returned on the initial socket and the command line is passed to the normal login shell of the user. The shell inherits the network connections established by rshd.

    Transport-level keepalive messages, which allow sessions to be timed out if the client crashes or becomes unreachable, are enabled unless the -n option is given.


Except for the last one listed below, all diagnostic messages are returned on the initial socket, after which any network connections are closed. An error is indicated by a leading byte with a value of 1 (0 is returned in step 9 above upon successful completion of all the steps prior to the execution of the login shell).

Can't fork; try again.
A fork() by the server failed.
Can't make pipe.
The pipe needed for standard error wasn't created.
Command too long.
The command line passed is > the size of the argument list (as configured into the system).
Locuser too long.
The name of the user on the client's machine is > 16 characters.
Login incorrect.
No password file entry for the username existed.
Permission denied.
The authentication procedure described above failed.
Remote directory.
The chdir command to the home directory failed.
Ruser too long.
The name of the user on the remote machine is > 16 characters.
<shellname>: ...
The user's login shell couldn't be started. This message, which is returned on the connection associated with standard error, isn't preceded by a flag byte.


The authentication procedure used here assumes the integrity of each client machine and the connecting medium. Though insecure, this procedure is useful in an "open" environment.