SFTP/SCP

scp and sftp are replacements for the old rcp and ftp utilities, respectively. They send secure information (such as your password) over an encrypted connection making them preferable to the old methods.

scp is useful for quickly sending a few files to and from machines. sftp is best for transferring large amounts of files interactively.

Using scp

To copy a file from another host, scp uses the format:

	scp source_file destination_file

If the source file or destination file are on a remote host, the format of either is:

	username@hostname:filename

For example, to copy a file called "file.txt" from your home directory on aldred to your current working directory do:

	scp username@aldred:~/file.txt .

The '~' character in the example above is a quick way of specifiying the home directory of the user ID you are connecting as.

Or send the file "updated.txt" to your home directory on aldred:

	scp updated.txt username@aldred:~/

Using sftp

sftp uses interactive commands, so to log onto a remote host you must first do:

	sftp username@hostname

Enter your password when prompted. Once logged in you can use standard FTP commands to list directories and send or receive files.

For example, to copy the file called "file.txt" from aldred and send a file called "updated.txt":

	sftp username@aldred
	username@aldred's password:
	sftp> ls
	.
	..
	Mail
	mail
	file.txt
	sftp> get file.txt
	Fetching /home/ucs/123/username/file.txt to file.txt
	sftp> put updated.txt
	Uploading updated.txt to /home/ucs/123/username/updated.txt
	sftp> quit

Other commands are available for dealing with large amounts of files and basic file management, see the sftp man page for more information.

Problems using scp & sftp

Most of the error messages from scp and sftp are self-explanatory, however on occasion you may see this message when connecting to a remote host:

	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
	Someone could be eavesdropping on you right now (man-in-the-middle attack)!
	It is also possible that the DSA host key has just been changed.

This means that the remote host looks different to how it did when you first connected to it. This is usually just something benign such as a software upgrade on the remote host, but it could also mean your connection is being interferred with. If you are sure that you want to continue you must remove the local copy of the host key.

This process differs for the two main versions of SSH: OpenSSH (and Sun SSH) or SSH.com's non-commercial client. The default SSH client on both time sharing systems is OpenSSH. This is also the default on Linux and Mac OS X systems.

To find out which version you are using type:

 ssh -V 

OpenSSH / Sun SSH

The result of ssh -V for OpenSSH will resemble one of the following, although the version numbers may differ:

OpenSSH_4.4p1, OpenSSL 0.9.8c 05 Sep 2006
Sun_SSH_1.1, SSH protocols 1.5/2.0, OpenSSL 0x0090704f

Edit the <homedir>/.ssh/known_hosts file. Find the line that starts with the hostname of the remote host you were trying to connect to and delete it. Save the file and then try reconnecting to the host.

If the known_hosts file contains lines that do not begin with recognisable hostnames, then your SSH client is "hashing" them as a security measure. The warning message that you received will include a line number which corresponds to the host in question: delete this line.

SSH.com client

The result of ssh -V for the SSH.com client will resemble the following, although the version and machine specification (the bit at the end) may differ:

ssh: SSH Secure Shell 3.1.0 (non-commercial version) on sparc-sun-solaris2.7

The default SSH client on aidan was the SSH.com client until late 2006.

To clear the local copy of the host key, remove the file called <homedir>/.ssh2/key_22_hostname.pub (where 'hostname' corresponds with the hostname of the host you were trying to connect to) and then try reconnecting to the host.

Leave Feedback