Secure SHell (SSH), Version 2
|
and a secure file copy between computers |
ssh [-l login_name] hostname [command] |
User_id:
mst3k
Computers:
localcompA, remotecompB
Input;
commands & output
|
localcompA:
/home/mst3k $ mkdir .ssh2 localcompA:
/home/mst3k/.ssh2 $ ssh-keygen
localcompA:
/home/mst3k/.ssh2 $ mv id_dsa_1024_a
mst3k_on_A |
| localcompA:
/home/mst3k/.ssh2 $ more identification # File: identification # Must be located on computer # you ssh from (localcompA) # Identifies your private key # filename for this computer IdKey mst3k_on_A localcompA:
/home/mst3k/.ssh2 $ more authorization
|
| localcompA: /home/mst3k/.ssh2 $ scp mst3k_on_A.pub mst3k@remotecompB:/home/mst3k/.ssh2 |
SSH provides "secure encrypted communications between two untrusted hosts over an insecure network." There can be no "password spoofing" since no passwords are exchanged. What needs to occur?
With these mechanisms in place, it becomes virtually impossible for anyone to "read" the information we exchange. Notice that "password" was not mentioned in the conditions above.
Basic rules for setting up your environment are:
|
|
|
NOTES:
"A" is a computer
mst3k has account on ComputerA
& .ssh2/ directory contains:
identification - name of file
that lists filenames of mst3k's
private keys, e.g.
mst3k_on_A (secret to A)
authorization - name of file
that lists filenames of public
keys allowed by mst3k, e.g.
mst3k_on_B.pub
hostkeys/ - subdirectory on (A)
that contains public keys for
computers accepted by A: names
are Key_port#_machineName
----------------------------
----------------------------
Run ssh-agent - starts ssh process
Run ssh-add - gives mst3k_on_A
to agent - requires passphrase
----------------------------
Run command on B via ssh:
'ssh address(B) -l mst3k DO_THIS'
A and B exchange "sessionKey" <--
A sends command "mst3k DO_THIS"
encrypted by sessionKey ----->
Result received and decrypted
using sessionKey
Tasks completed:
erase "sessionKey"
& disconnect from B
|
|
First, SSH uses an encryption technique that does not require the transfer of passwords between accounts. Using a Public Key Infrastructure (PKI), SSH generates and employs a public/private key-pair to identify a user to an account and to allow other users access to the account. Keep in mind that one's public and private keys are inverses of one another - encrypt, then decrypt and you get back the original string.
Your Private Key is yours only. Do not share this with anyone else. It should remain on the computer that generated it, unless you have good reason to copy it to another account. You'll know how and why in that case.
Your Public Key may be given to anyone who is willing to accept it. If you accept someone's Public Key, reference it by name in your authorization file, and keep a file by that name in your .ssh2 subdirectory, you are trusting the person to roam around your account, as if s/he were you. Be careful about accepting and using an SSH Public Key in this way.
How does this PKI verification work? Let's say that you trust me to access your account. I give you my Public Key that was created on the computer I use on a daily basis. You put this file into your .ssh2 directory and add the name of the file to the list in your authorization file there. When I want to work in your account from my computer, I can do so using the following steps:
- Beginning on my own computer, I run ssh-agent to create a process act on my behalf.
- Next I run ssh-add, which means I give the agent my Private Key and it is added to the agent's list.
- Before ssh-agent will accept my Private Key however, I must supply the passphrase that goes with it. If I could not supply the passphrase, the ssh-agent would refuse to take my Private Key. Assume my identification succeeded.
- Now I issue an SSH command on my computer (localcompA) asking that yours (remotecompB) run this command from your account (-l your_user_id) there.
What happens?
- The computers contact one another and "prove" their identities. Do I have a public key in my .ssh2/hostkeys subdirectory that is from your computer. If there is, fine; if not, I can only continue if I'll accept one, and store it in my .ssh2/hostkeys subdirectory.
- Our computers exchange a symmetric (used for both encryption and decryption) Session Key to use for encryption during this session.
- Your computer needs to authorize me and sends a challenge to my computer. The challenge is encrypted using your authorized public keys (followed by the Session Key) until the following occurs ...
- My computer decrypts the message using the Session Key, then decrypts the result with my Private Key. The result is encrypted using the Session Key before sending it back to your computer.
- Your computer decrypts the returned message, and if it is the same as your original challenge, your computer authorizes me and mine - we must have had a matching Private Key. If no returned message were the same as the original, the game's over and your computer would refuse my access. Assume we're authorized ...
- Our computers will now encrypt and decrypt all exchanges using the Session Key.
- My computer is satisfied with my identification (I gave the correct passphrase), so it uses the Session Key to encrypt my command and sends it to your computer - to be run as if you were giving the command there.
- Your computer has authorized me to run commands remotely, so it decrypts the message, runs the command in your home directory, encrypts the result using the Session Key, and sends it back to me.
The interchange may be continued as long as the agent process runs. The ssh-agent can hold additional private keys, enabling the process to be used by more than one identifiable user.
A schematic
of this process can be viewed by clicking here.
User_ids:
mst3k, user1, user2
Computers:
localcompA, remotecompB
Input; commands
& output
"<"
indicates part of line was overlaid by prompt
Note: Before using ssh commands from localcompA to remotecompB, start the SSH agent process and export the environment variables it generates for you (use copy & paste). Run ssh-add to associate your private key with the ssh-agent process. For options, see the manpages for ssh-agent and ssh-add.
| localcompA:
/home/mst3k/.ssh2 $ ssh-agent SSH2_AUTH_SOCK=/tmp/ssh-mst3k/ssh2-42920-agent; export SSH2_AUTH_SOCK; SSH2_AGENT_PID=56444; export SSH2_AGENT_PID; echo Agent pid 56444; localcompA: /home/mst3k/.ssh2 $ 3k/ssh2-42920-agent; export SSH2_AUTH_SOCK < localcompA: /home/mst3k/.ssh2 $ SSH2_AGENT_PID=56444; export SSH2_AGENT_PID localcompA: /home/mst3k/.ssh2 $ ssh-add Adding identity: /home/mst3k/.ssh2/mst3k_on_A.pub Need passphrase for /home/mst3k/.ssh2/mst3k_on_A (1024-bit dsa, mst3k@localcompA, Wed Oct 24 2001 19:03:23). Enter passphrase: ******** |
Note: When you go to a remote computer for the first time, you will be asked if you wish to accept its public key. The keyfiles from hosts you have used before
(see ) are stored in the directory $HOME/.ssh2/hostkeys. In the example below mst3k requests a listing of files in her .ssh2/hostkeys directory on the remote computer B.
|
localcompA:
/home/mst3k/.ssh2 $ ssh remotecompB 'ls
.ssh2' |
Note: The above listing was on remotecompB for mst3k's account. mst3k's .ssh2 directory on localcompA is different (see below). The user2.pub entry above (on remotecompB) enables user2 to run commands anywhere in mst3k's account on remotecompB. mst3k has allowed this by accepting user2's public key. By contrast, in the example below only user1 might be able to run commands in mst3k's account on localcompA. An aside ... note that the files in the hostkeys subdirectory show that mst3k has used ssh to connect with remotecompB and anothercompC.
|
localcompA:
/home/mst3k/.ssh2
$ ls -F
localcompA:
/home/mst3k/.ssh2 $ ls hostkeys
|
Note: In the following example, mst3k requests a long listing of the entries in user1's .ssh directory. It is no surprise to see that mst3k's public key has been given to & accepted by user1 and referenced in user1's authorization file.
| localcompA:
/home/mst3k $ ssh -l user1 remotecompB
'ls -l /home/user1/.ssh2' total 72 -rw-r--r-- 1 user1 staff 224 Oct 24 15:11 authorization drwx------ 2 user1 staff 512 Oct 16 16:48 hostkeys -rw-r--r-- 1 user1 staff 216 Oct 24 15:11 identification -rw------- 1 user1 staff 512 Oct 16 16:50 random_seed -rw------- 1 user1 staff 888 Jan 15 2001 user1 -rw-r--r-- 1 user1 staff 749 Jan 15 2001 user1.pub -rw-r--r-- 1 user1 staff 745 Jan 15 2001 mst3k_on_A.pub |
JTAN() - links to applications of SSH for Windows, SecureCRT, SSH for NT and the Palm Pilot:
http://www.jtan.com/resources/ssh.htmlSSH Communications Security:
http://www.ssh.fi/The SSH Frequently Asked Questions (FAQ):
http://www.onsight.com/faq/ssh/ssh-faq.htmlNiftyTelnet for the Macintosh:
http://www.lysator.liu.se/~jonasw/freeware/niftyssh/Links2Go: the most commonly cited pages for SSH
http://www.links2go.com/topic/SSH