Common Administration Tasks
只搜尋這本書
以 PDF 格式下載這本書

Accessing Remote Files and Systems

7

This chapter has the following sections:
Logging In to a Remote Systempage 63
Executing Commands on a Remote System Without Logging Inpage 65
Checking Who Is Logged In to a Remote Systempage 65
Copying a File or a Directory Over a Networkpage 66
This chapter describes the commands you can use to access other systems on the network and to copy files or directories to or from remote systems.

Logging In to a Remote System

You use the rlogin(1) command to log in to other systems on the network.

· How to Log In to a Remote System

  1. Type rlogin system_name and press Return. The system displays a password prompt if the remote system requires a password to log in.

  2. Type the password for your account on the remote system (if required) and press Return.

    The command prompt for the remote system is displayed.

· How to Log Out From a Remote System

* Type exit and press Return.

· How to Log In to a Remote System With a Different User Name

  1. Type rlogin -l username system_name and press Return. The password prompt is displayed if the remote system requires a password for the specified username.

  2. Type the password for the account on the remote system (if required) and press Return.

    The command prompt for the remote system is displayed.

· How to Allow Remote Login by the Superuser

  1. Type rlogin system_name and press Return.

  2. Type su and press Return.

  3. Type the root password and press Return.

  4. Edit the file /etc/default/login.

    Put a hash mark (#) at the beginning of the following line:


  CONSOLE=/dev/console  

This makes the line a comment and CONSOLE will not be set. If CONSOLE is set, the superuser can log in only on the console. You can now log in to the system as superuser from a remote system.
  1. Type exit and press Return to exit the superuser shell.

  2. Type exit and press Return to log out from the remote system.

Executing Commands on a Remote System Without Logging In

Use the rsh(1) (remote shell) command to execute a command on a remote system. rsh cannot be used to run interactive commands on a remote system; you must log in to the system to run interactive commands.

· How to Execute a Command on a Remote System

* Type rsh system_name command and press Return.
If the user from the local system does not have permission to execute remote commands on the remote system, the local system displays one of the following messages:
Permission denied
Login incorrect

The following example executes the uptime command on the system mars:

  % rsh mars uptime  
    4:58pm  up 5 day(s),  7:25,3 users,  load average: 0.04, 0.01, 0.02  

Checking Who Is Logged In to a Remote System

You can check who is logged in to a remote system with the rusers command.
The rusers command lists remote systems followed by a list of all the users logged in on the system. The rusers -l option lists the following for all users logged in to remote systems:
  • user name
  • shell window
  • login time and date
  • amount of time logged in
  • remote machine from which the user logged in

· How to Find Out Who Is Logged In to Remote Systems

  1. Type rusers -l [system_name] and press Return. If you do not specify a system name, users logged on to all the systems on the network are shown.

The output of the rusers -l command is similar to the following:

  jane      pluto:console       Nov 18 09:19  
  darcy     mars:ttyp1          Nov 17 10:17        8 (jupiter)  

Copying a File or a Directory Over a Network

You can copy a file or directory from one system on the network to another with one of the following commands:
  • rcp (remote copy)--Copies files or directories in either direction between your local system and a remote system on your network.
  • ftp (file transfer)--Copies files (but not directories) in either direction between local and remote systems, when the systems are on different networks.

Note - To copy a file, you must have read permission. To copy a directory, you must have read and execute permission.

Copying a File or Directory With the rcp Command

Use the rcp command to copy a file or directory between local and remote systems on the same network.

CAUTION Caution - Copying a file between a local and a remote system overwrites a file with the same name on the destination system. However, copying directories between local and remote systems does not overwrite identically named directories; instead the copied directory becomes a subdirectory within the identically named directory.

· How to Copy a Directory to a Remote System
* Type rcp -r directory_name remote_system_name:[remote_directory_name] and press Return.
If you do not specify a name for the directory on the remote system, it will have the same name as the directory on the local system.
The following example shows how to copy a directory to a remote system:

  % rcp -r doc jupiter:docdir  

· How to Copy a File to a Remote System
* Type rcp filename remote_system_name:[remote_filename] and press Return. If you do not specify a name for the file on the remote system, it will have the same name as the file on the local system.
The following example copies a file to a remote system:

  % rcp main.c mars:  

· How to Copy a Directory From a Remote System
* Type rcp -r remote_system_name:directory_name [local_directory_name] and press Return.
If you do not specify local_directory_name, the directory that is copied to the local system will have the same name as the directory on the remote system.
This example copies a directory from a remote system to the current directory:

  % rcp -r saturn:docdir .  

· How to Copy a File From a Remote System
* Type rcp remote_system_name:filename [local_filename] If you do not specify local_filename, the file that is copied to the local system will have the same name as the file on the remote system.
The following example shows how to copy a file from a remote system to the current directory:

  % rcp mars:test.c .  

Copying a File With the ftp Command

To copy files from your local system to a remote system, or from a remote system to your local system, you can use the ftp command. You cannot copy directories with ftp.
The ftp command is especially useful for transferring files between local and remote systems on different networks. See the ftp(1) manual page for complete details about the ftp command.

CAUTION Caution - Copying a file between systems overwrites a file with the same name on the destination system.

· How to Copy a File to a Remote System
  1. Type ftp remote_system_name and press Return.

  2. Type the user name for your account on the remote system and press Return.

  3. Type the password for your account on the remote system (if required) and press Return.

  4. At the ftp> prompt, type put filename remote_filename and press Return.

  5. Type quit and press Return.

· How to Copy a File From a Remote System
  1. Type ftp remote_system_name and press Return.

  2. Type the user name for your account on the remote system and press Return.

  1. Type the password for your account on the remote system (if required) and press Return.

  2. At the ftp> prompt, type get filename local_filename and press Return.

  3. Type quit and press Return.


Note - The ftp command does not duplicate file permissions when copying files between systems. After you have copied the files, you may need to use the chmod command to reset the file permissions.

The following example shows how to copy a file from the remote system (jupiter) to the local system (mars):

  % ftp jupiter  
  220 jupiter FTP server (UNIX(r) System V Release 4.0) ready  
  Name (mars:john):  
  331 Password required for john.  
  Password:  
  230 User john logged in.  
  ftp>get ~henry/test.c  
  200 PORT command successful.  
  150 ASCII data connection for /home/henry/test.c (IP address)  
  (20480 bytes).  
  226 ASCII Transfer complete.  
  local: /home/john/test.c remote: ~henry/test.c  
  21428 bytes received in 0.27 seconds (78 Kbytes/s)  
  ftp> quit  
  %