SCP Secure File Transfer on Mac and Linux

A companion page ssh_putty.html describes setting up sftp file transfer for a user with a Windows PC. Mac and Linux generally have sftp built in, so this page is a quick introduction to setting up the keys only.

Getting a command-line prompt

The SSH family of program are command-line only, so the first step is to open a terminal window. If you use Linux regularly you probably know how to do this; otherwise look for xterm or something like that in the menus (depends on the specific Linux distribution in use).

On a mac, start by opening the Finder - That's the friendly little face icon in the lower left corner of the screen.

In the Finder select Applications in the left-side menu, then open the Utilities folder.

and within Utilities, select "Terminal".

Mac/Linux: generating keys

Keys are stored in the $HOME/.ssh folder, probably named id_dsa or id_rsa for the private key and the same name with a .pub suffix for the public key. If they already exit, nothing more needs to be done.

If the keys do not exist, run the ssh-keygen program. The default answers are probably acceptable. Here's an example of a run generating a dummy key.

bash-3.2$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
95:c5:d2:17:7b:45:80:0c:61:d9:d2:6e:60:8a:a1:c6 username@mypc.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|          +X..o+o|
|         .*oB . .|
| +  . . o  o= . .|
|    S . ..  o  . |
|   .    E  .     |
|      .  .    .  |
|     B o . +     |
|                 |
|                 |
+-----------------+
bash-3.2$ cd .ssh
bash-3.2$ pwd
/Users/username/.ssh
bash-3.2$ ls -la
total 32
drwx------   8 username  username   272 Feb 27 13:50 .
drwxr-xr-x+ 52 username  username  1768 Feb 27 13:43 ..
-rw-------   1 username  username  1679 Feb 27 13:50 id_rsa
-rw-r--r--   1 username  username   407 Feb 27 13:50 id_rsa.pub
-rw-r--r--   1 username  username   651 Dec 30  2010 known_hosts
bash-3.2$ cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
(deleted)
-----END RSA PRIVATE KEY-----
bash-3.2$ cat id_rsa.pub
ssh-rsa AAAAB3NzVC1yc2EAAAADAQABAAABAQC7Nf4n3NZUAIojAU8nqIpm20Fm1qP4LkS5
eVFYwp79F/XjNCG3LdX2SZVf2EQJBLcfaIiklK4i2YiCqHK1DXDd5zzDXrUfk55g91XDc9an
r2wwvXKcFUFM4IpTZFV0Y5oxOlIXxAp8ovQZe7KvLdToVm5XooR5dHgYNPlLqnVmBxuOQQFv
fB0wjCvdBbpDwvHuUrPYcE0vFV7Om3gW+wPHx+wBfKcwOw2InRJMNAnZxSiBE1LkzmYiRJrA
PIrgjzDDeb+VHdBuCV+gq+bf6Md5c03mlmzeYOPe0PpwcI9jMDgbErBWot34vpErGNkHLIZT
NX2RF5f/s2HcVVxQr251 username@mypc.example.com

as with PuTTY, you never share the private key with anyone else. The public key (id_rsa.pub here) needs to be added to the authorized_keys file on the remote server.

Mac/Linux: File transfer

The program used to transfer files to and from the remote server is sftp and it works the same as the psftp program described in the ssh_putty page.


Last revision $Id: ssh_mac_linux.html,v 1.2 2013/03/01 03:13:46 jrothwei Exp $