Purchase  Copyright © 2002 Paul Sheer. Click here for copying permissions.  Home 

next up previous contents
Next: 13. LINUX Resources Up: rute Previous: 11. User Accounts and   Contents

Subsections

12. Using Internet Services

This chapter summarizes remote access and the various methods of transferring files and data over the Internet.

12.1 ssh, not telnet or rlogin

telnet is a program for talking to a UNIX network service. It is most often used to do a remote login. Try

 
 
telnet <remote_machine>
telnet localhost

to log in to your remote machine. It needn't matter if there is no physical network; network services always work regardless because the machine always has an internal link to itself.

rlogin is like a minimal version of telnet that allows login access only. You can type

 
 
rlogin -l <username> <remote_machine>
rlogin -l jack localhost

if the system is configured to support remote logins.

These two services are the domain of old world UNIX; for security reasons, ssh is now the preferable service for logging in remotely:

 
ssh [-l <username>] <remote_machine>

Though rlogin and telnet are very convenient, they should never be used across a public network because your password can easily be read off the wire as you type it in.

12.2 rcp and scp

rcp stands for remote copy and scp is the secure version from the ssh package. These two commands copy files from one machine to another using a similar notation to cp.

 
 
rcp [-r] [<remote_machine>:]<file> [<remote_machine>:]<file>
scp [-l <username>] [-r] [<remote_machine>:]<file> [<remote_machine>:]<file>

Here is an example:

 
 
 
 
5 
 
 
 
 
10 
[psheer@cericon]# rcp /var/spool/mail/psheer \
 divinian.cranzgot.co.za:/home/psheer/mail/cericon
[psheer@cericon]# scp /var/spool/mail/psheer \
 divinian.cranzgot.co.za:/home/psheer/mail/cericon
The authenticity of host 'divinian.cranzgot.co.za' can't be established.
RSA key fingerprint is 43:14:36:5d:bf:4f:f3:ac:19:08:5d:4b:70:4a:7e:6a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'divinian.cranzgot.co.za' (RSA) to the list of known hosts.
psheer@divinian's password: 
psheer               100% |***************************************|  4266 KB    01:18

The -r option copies recursively and copies can take place in either direction or even between two nonlocal machines.

scp should always be used instead of rcp for security reasons. Notice also the warning given by scp for this first-time connection. See the ssh documentation for how to make your first connection securely. All commands in the ssh package have this same behavior.

12.3 rsh

rsh (remote shell) is a useful utility for executing a command on a remote machine. Here are some examples:

 
 
 
 
5 
 
 
 
 
[psheer@cericon]# rsh divinian.cranzgot.co.za hostname
divinian.cranzgot.co.za
[psheer@cericon]# rsh divinian.cranzgot.co.za \
   tar -czf - /home/psheer | dd of=/dev/fd0 bs=1024
tar: Removing leading `/' from member names
20+0 records in
20+0 records out
[psheer@cericon]# cat /var/spool/mail/psheer | rsh divinian.cranzgot.co.za \
   sh -c 'cat >> /home/psheer/mail/cericon'

The first command prints the host name of the remote machine. The second command backs up my remote home directory to my local floppy disk. (More about dd and /dev/fd0 come later.) The last command appends my local mailbox file to a remote mailbox file. Notice how stdin, stdout, and stderr are properly redirected to the local terminal. After reading Chapter 29 see rsh(8) or in.rshd(8) to configure this service.

Once again, for security reasons rsh should never be available across a public network.

12.4 FTP

FTP stands for File Transfer Protocol. If FTP is set up on your local machine, then other machines can download files. Type

 
ftp metalab.unc.edu

or

 
ncftp metalab.unc.edu

ftp is the traditional command-line UNIX FTP client, [``client'' always indicates the user program accessing some remote service.]while ncftp is a more powerful client that will not always be installed.

You will now be inside an FTP session. You will be asked for a login name and a password. The site metalab.unc.edu is one that allows anonymous logins. This means that you can type anonymous as your user name, and then anything you like as a password. You will notice that the session will ask you for an email address as your password. Any sequence of letters with an @ symbol will suffice, but you should put your actual email address out of politeness.

The FTP session is like a reduced shell. You can type cd, ls, and ls -al to view file lists. help brings up a list of commands, and you can also type help <command> to get help on a specific command. You can download a file by using the get <filename> command, but before you do this, you must set the transfer type to binary. The transfer type indicates whether or not newline characters will be translated to DOS format. Typing ascii turns on this feature, while binary turns it off. You may also want to enter hash which will print a # for every 1024 bytes of download. This is useful for watching the progress of a download. Go to a directory that has a README file in it and enter

 
get README

The file will be downloaded into your current directory.

You can also cd to the /incoming directory and upload files. Try

 
put README

to upload the file that you have just downloaded. Most FTP sites have an /incoming directory that is flushed periodically.

FTP allows far more than just uploading of files, although the administrator has the option to restrict access to any further features. You can create directories, change ownerships, and do almost anything you can on a local file system.

If you have several machines on a trusted LAN (Local Area Network--that is, your private office or home network), all should have FTP enabled to allow users to easily copy files between machines. How to install and configure one of the many available FTP servers will become obvious later in this book.

12.5 finger

finger is a service for remotely listing who is logged in on a remote system. Try finger @<hostname> to see who is logged in on <hostname>. The finger service will often be disabled on machines for security reasons.

12.6 Sending Files by Email

Mail is being used more and more for transferring files between machines. It is bad practice to send mail messages over 64 kilobytes over the Internet because it tends to excessively load mail servers. Any file larger than 64 kilobytes should be uploaded by FTP onto some common FTP server. Most small images are smaller than this size, hence sending a small JPEG [A common Internet image file format. These are especially compressed and are usually under 100 kilobytes for a typical screen-sized photograph.] image is considered acceptable.

12.6.1 uuencode and uudecode

If you must send files by mail then you can do it by using uuencode. This utility packs binary files into a format that mail servers can handle. If you send a mail message containing arbitrary binary data, it will more than likely be corrupted on the way because mail agents are only designed to handle a limited range of characters. uuencode represents a binary file with allowable characters, albeit taking up slightly more space.

Here is a neat trick to pack up a directory and send it to someone by mail.

 
 
tar -czf - <mydir> | uuencode <mydir>.tar.gz \
    | mail -s "Here are some files" <user>@<machine>

To unpack a uuencoded file, use the uudecode command:

 
uudecode <myfile>.uu

12.6.2 MIME encapsulation

Most graphical mail readers have the ability to attach files to mail messages and read these attachments. The way they do this is not with uuencode but in a special format known as MIME encapsulation. MIME (Multipurpose Internet Mail Extensions) is a way of representing multiple files inside a single mail message. The way binary data is handled is similar to uuencode, but in a format known as base64.

Each MIME attachment to a mail message has a particular type, known as the MIME type. MIME types merely classify the attached file as an image, an audio clip, a formatted document, or some other type of data. The MIME type is a text tag with the format <major>/<minor>. The major part is called the major MIME type and the minor part is called the minor MIME type. Available major types match all the kinds of files that you would expect to exist. They are usually one of application, audio, image, message, text, or video. The application type means a file format specific to a particular utility. The minor MIME types run into the hundreds. A long list of MIME types can be found in /etc/mime.types.

If needed, some useful command-line utilities in the same vein as uuencode can create and extract MIME messages. These are mpack, munpack, and mmencode (or mimencode).


next up previous contents
Next: 13. LINUX Resources Up: rute Previous: 11. User Accounts and   Contents