Опубликован: 06.08.2012 | Доступ: свободный | Студентов: 1327 / 46 | Оценка: 5.00 / 5.00 | Длительность: 53:41:00
Лекция 24:

Basic network access: clients


As mentioned above, telnet is an older, unencrypted program that connects to a shell on a remote system. You might find it of use when connecting to a system that doesn't have ssh. Be very careful not to use valuable passwords, since they are transmitted in the clear. Apart from that, you use it pretty much in the same way as ssh:

$ telnet freebie
Connected to freebie.example.org.
Escape character is '^]'.
login: grog
Password:    (no echo)

FreeBSD/i386 (wantadilla.example.org) (ttypj)
Last login: Mon Oct 14 17:51:57 from sydney.example.org
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
    The Regents of the University of California.  All rights reserved.

FreeBSD 5.0-RELEASE (FREEBIE) #0: Tue Dec 31 19:08:24 CST 2002

You have new mail.
If I have seen farther than others, it is because I was standing on the
shoulders of giants.
  -- Isaac Newton

In the sciences, we are now uniquely privileged to sit side by side
with the giants on whose shoulders we stand.
  -- Gerald Holton

If I have not seen as far as others, it is because giants were standing
on my shoulders.
  -- Hal Abelson

In computer science, we stand on each other's feet.
  -- Brian K. Reid
$ tty

Once you get this far, you are connected to the machine in an almost identical manner as if you were directly connected. This is particularly true if you are running X. As the output of the tty command shows, your "terminal" is a pseudo-tty or pty (pronounced "pity"). This is the same interface that you will have with an xterm.

It's worth looking in more detail at how the connection is established:

  • The first line (Trying...)appears as soon as telnet has resolved the IP address.
  • The next three lines appear as soon as it has a reply from the other end. At this point, there can be a marked delay before telnet continues. telnet performs a reverse DNS lookup to find the name of your system. If you get a delay here, it could be an indication that your reverse lookup is not working correctly. After DNS times out, it will continue normally, but the delay is a nuisance.
  • Logging in is almost exactly the same as logging in locally. Normally you won't be able to log in directly as root, unless you have set /dev/ptyx as secure in your /etc/ttys (see page 197 for further details). It's not a good idea to set your ptys as secure. Use su instead if you want to become root.

When you log in via telnet, there's a good chance that your TERM environment variable will be set incorrectly. See Table 7-3 on page 130 for more details. TERM describes the display at your end of the display, not the other end. If you're running an xterm, this shouldn't be a problem: probably the name xterm will propagate to the other end. If you're using a character-oriented display (/dev/ttyvx), however, your TERM variable will probably be set to cons25, which many systcodes don't know. If the rcodeote systcode refuses to start programs in full-screen modes, try setting the TERM variable to ansi.

To exit telnet, you just log off. If you run into problems, however, like a hung network, you can also hit Ctrl-] to enter telnet command mode, and from there enter quit:

$ ^]
telnet> quit

If you hit Ctrl-] by accident, just hit Enter to return to the telnet session.

Secure telnet

Recent releases of FreeBSD telnet include a secure connection option. You can recognize it by the different messages that appear when you connect:

$ telnet freebie
Connected to freebie.example.org.
Escape character is '^]'.
Trying SRA secure login:
User (grog):
[SRA accepts you ]

There's no particular reason to use this version of telnet; it's non-standard, and you're still better off with ssh.

Using telnet for other services

The way we have used telnet so far, it connects to the default port, telnet (number 23, as you can see in the file /etc/services). This isn't the only possibility, though: you can tell telnet which port to connect to. In "Electronic mail: servers" , Electronic mail: servers, we'll see how to communicate with sendmail using telnet on port smtp page 502, and how to communicate with POP on port pop, page 504. There are many other such uses.

Copying files

The other basic function involves copying files between systems. The traditional tools are ftp and rcp. Neither use encryption, so it's preferable to use scp, a variant of ssh. Nevertheless, ftp has its uses. About the only use for rcp is on systems that don't support scp, or systems where security is not an issue, and scp is so slow that it's not practical. The good news: you use rcp in pretty much the same manner as scp: scp was designed to be compatible with rcp, so you don't need to learn anything else if you want to use it.


scp is a variant of ssh used for remote copying. The same access considerations apply as for ssh. The syntax for copying is similar to the syntax used by NFS: to copy a file /var/log/messages from presto to the file prestomessages on the local machine, you might enter:

$ scp presto:/var/log/messages prestomessages

As with ssh, if you need to authenticate as a different user, you can use the form user@system.scp does not support the -l option to specify the user name.

scp has a number of options reminiscent of cp:

  • • Use the -p option to preserve modification times and permissions where possible. Note that this means you can't use ssh's -p option to specify an alternative port. scp uses the -P option for this instead.
  • • Use the -r option to recursively copy directories. You don't have to supply full path names to scp; you can write things like:
$ scp remotehost:file .

This looks for a file called file in your home directory on the remote machine and copies it to your current local directory. Note the difference: there is no way for scp to know a different remote directory, so relative paths are always relative to the home directory on that machine.