How to Use rlogin, rsh and telnet to login and run commands on a remote host
Establishing a Remote Login Session
A remote login session enables you to access a remote host from your current machine and to use the resources of the remote host. This section describes how to log in to your account remotely from another system on a network.
Introducing an Example Network
A network is a connection of computer systems that enables an exchange of information among the systems. A network also enables you to access your user account from another system. Two types of networks are:
- Local area network (LAN) – A network that covers a small area, usually less than a few thousand feet or meters
- Wide area network (WAN) – A network that can span thousands of miles or kilometers.
A host is a computer system on a network. The local host is your current working system. A remote host is a different system that you access from your localhost.
The ~/.rhosts File
When a remote user requests a local host for login access, the local host searches the local /etc/passwd ﬁle for an entry for that user. If an entry for the user exists, the user can log in to the local host from a remote system. If a password is associated with the account, the remote user supplies the password to gain system access. If no entry exists in the local /etc/passwd ﬁle for the remote user, the remote user cannot access the system.
The ~/.rhosts ﬁle provides another authentication procedure to determine if a remote user can access the localhost with the identity of a local user. This procedure bypasses the password authentication. The system checks the ~/.rhosts ﬁle in the home directory of the local host user to determine if the remote user can access the system.
Using the rlogin Command
You can use the rlogin command to establish a remote login session on another system. The syntax for the rlogin command is:
$ rlogin hostname
The following example shows you how to use the rlogin command to log in to another system remotely. You can use the uname -n command to verify the name of the remote system.
$ rlogin host2 Last login: Mon Mar 6 16:22:12 from host1 Sun Microsystems Inc. SunOS 5.9 Generic February 2000 $ uname -n host2 $ pwd /export/home/user1 $ exit Connection to host2 closed. $
You can use the rlogin command with the -l option to specify a different user name for a remote login session. The syntax for the rlogin -l command is:
$ rlogin -l username hostname
To log in as a different user, you can use the following information to identify and log in to the account:
- The host name
- The user name
- The password for the user on the remote host
The following example shows you how to log in remotely to the host2 system as another user, user2:
$ rlogin -l user2 host2 Password: Last login: Mon Mar 6 16:36:35 from host2 Sun Microsystems Inc. SunOS 5.9 Generic February 2000 ... (output truncated) $ pwd /export/home/user2 $ uname -n host2 $ exit Connection to host2 closed. $
Running a Program on a Remote System
You use the rsh command to run a program on a remote system without having to log in to the remote system. The syntax for the rsh command is:
rsh hostname command
The following example shows you how to use the rsh command as user1 to perform the ls command remotely on the host2 system.
$ rsh host2 ls
The following example shows how user1 runs the rsh command to perform the ls /var/mail command on the remote system named host2.
$ rsh host2 ls /var/mail
The output from these commands shows information from the host2 system.
Terminating a Process Remotely by Logging In to Another System
If your system is not responding to your keyboard or to mouse input, the window system might be frozen. You can use the rlogin command to access your system remotely from another system. Then you can perform the pkill command to terminate the corrupted session.
The following example shows you how to use the rlogin command to terminate a process remotely on the host2 system.
$ rlogin host2 Password: Last login: Fri Feb 04 16:50:30 from host1 Sun Microsystems Inc. SunOS 5.9 Generic February 2000 $ pkill shell or $ pkill -9 shell
Using the telnet Command
You can use the telnet command to log in to a remote system and work in that environment. The syntax for the telnet command is:
The following example shows how to use the telnet command to connect to a remote system called host2.
$ telnet host2 Trying host2 Connected to host2 Escape character is ’^]’. SunOS 5.9 login: user2 Password: Last login: Mon May 6 14:13:40 from host1 Sun Microsystems Inc. SunOS 5.9 Generic May 2002 $ uname -n host2 $ exit Connection to hostname closed by foreign host. $
NOTE: – The telnet command always prompts for the user’s password, and does not use the .rhosts ﬁle.