Inside SSH, Part 1
Pages: 1, 2
Prerequisite: A Word About Cryptography and Keys
Since we're going to talk a fair bit about asymmetric cryptography and keys in this article, I thought it would be more convenient to gather all what you need to know about them before we begin. That way, I won't have to bother you with these (fascinating) technical details later on.
Asymmetric cryptography relies on the use of two encrypting and decrypting devices called keys. Roughly speaking, you can think of keys as of complex, machine-generated passwords. In a more technical way, we could say that they are random streams of binary data. One of these keys is called a public key and is distributed freely by its owner, to anyone who wishes to communicate securely with him. To send an encrypted message to the owner of the key pair, correspondents just need a special encrypting program to which they will give the cleartext message and the key.
Here's what makes the system interesting: the resulting encrypted message (or cyphertext) can only be decrypted by the private key, the one that the owner does not distribute and protects at all costs. This means that even the other correspondents who own the public key won't be able to decrypt the message.
As you can see, this solves the major drawback of symmetric encryption. Since, with this system, the same key can encrypt and decrypt the messages, it must be exchanged securely by the two correspondents before they can begin to talk to each other, which is almost infeasible over the Internet. Also, there can only be two correspondents for a key, since giving the key to a third person would put the communications of the first two at risk. Just imagine the number of keys we would need in our everyday workflow!
These keys can also be used to prove the identity of someone. In fact, a digital signature is considered in many countries to be as valid as a paper-and-pencil one, a whole new concept that is not without legal issues. It works in quite a simple way: a mathematical operation is performed on a document and the result is encrypted with the private key.
The encrypted result is then sent along with the document and the sender's public key. In order to check the signature, the recipient needs to perform the same mathematical operation and compare it with the result sent along with the document, which has been previously decrypted with the public key. The key pair is signed by a certification authority (CA) that guarantees (to varying extents) that it belongs to someone.
Servers can also prove their identity to each other through a cryptographic exchange: instead of encrypting a document, the owner of the public key sends an encrypted random string and waits for the other side to send it back decrypted, meaning that it owns the private key. There is more to it, actually, but you get the idea. Notice that, with such a system, the actual private key never leaves the computer on which it is stored. This makes key-based authentication extremely difficult to subvert, since the attacker cannot even try to steal a key in the same manner as a password that travels on a network -- even if it is in an encrypted form.
Since keys are extremely long, comparing them bit by bit would definitely not be practical for the average user. Therefore, cryptography has come up with a value known as the key fingerprint that is derived from the key thanks to some advanced math. Much like there are theoretically no two human beings with the exact same fingerprints, there should not be two keys with the same fingerprint. As you can imagine, this is a theory, since keys are extremely long and fingerprints extremely short.
Nevertheless, the risk is considered acceptable. In situations where you would need to check two instances of a key file to compare that they are identical, you could turn to their fingerprints instead of checking the files manually. Should you use the checksums provided by many download sites in order to check the integrity of the files you get, you should already be familiar with the system. In fact, SSH and SHA1 checksums are not entirely strangers to each other.
If you want to learn more about the world of keys, you can have a look at our "Encrypted Mail on Mac OS X" article that provides an introduction to the system, as well as links that you may find of interest.
When SSH is Not SSH
In this article, we use the acronym SSH to designate both the SSH protocol and the SSH client or server running on Mac OS X computers. However, for the sake of clarity, we should pause for a moment and make sure that we do know the principal meanings SSH can have.
There are in fact two versions of the SSH protocol, called SSH1 and SSH2. Indeed, weaknesses found in the SSH1 integrity check system have, among others, prompted the development of SSH2, which is even more secure. However, for various technical reasons, deployment of SSH2 has been slower than expected and SSH1 is still widely in use. Indeed, while it is much more flexible than SSH1, SSH2 can be at times more complex -- its structure is a lot more modular, and it uses different algorithms.
There are many SSH clients and servers; some commercial, some not. In Mac OS X, Apple chose to use OpenSSH, a well-known, time-tested, open source version of SSH that is capable of handling both SSH1 and SSH2, all in the same package. If you're already used to another SSH setup, you may notice some subtle differences in the configuration options.
This is normal since, although various distributions are similar in many points, they all have their particularities. Installations that do not use OpenSSH often rely on two programs, SSH2 and SSH1, capable of calling each other to handle the appropriate connection requests -- which is not without administration headaches, as it forces you to set up two SSH servers instead of one for optimal security.
The OpenSSH suite includes in fact many programs, most of which we are going to use at one point or another: scp, which allows you to remotely and securely copy files; sftp, which replaces the standard, insecure ftp command; and utilities that are used at various stages of the key creation and management process, such as ssh-keygen, which generates cryptographic keys.
The software is developed outside the U.S., using code from roughly 10 countries, and is freely useable and reuseable by everyone, under a BSD license.
You can find a detailed introduction to OpenSSH and its history on this page.
Next Time
Now that we have all of our prerequisites out of the way, we can roll up our sleeves and get to work. Join me next Tuesday for part two, where we fire up the Terminal and get secure. See you then!
FJ de Kermadec is an author, stylist and entrepreneur in Paris, France.
Return to the Mac DevCenter
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 12 of 12.
-
SSH secured AFP vs command line SSH
2004-07-14 13:01:48 Gabriel_deKadt [Reply | View]
I find connecting to a remote server with any flavour of AFP from a Panther client a real waste of time. There's the obvious hit waiting for icons to load (.DS_Store files can be a real pain) but then the problems with the Finder clogging up with knock-on to file system dialogues within applications make it a real no-no for me. I've learnt some basic shell stuff just to get round this poor performance and am reaping rewards. I now connect with SSH via the Terminal and use RsyncX (great stuff), Stuffit Deluxe's command line tool and scp. I'm now, if not ecstatic, then at least happy and productive in a resource fork and meta data friendly stylee.
-
ssh secure AFP connection with OSX 10.3.4 (not server version)
2004-07-11 02:01:40 Felix-fi [Reply | View]
Anybody figure out how to make the connection to an AFP server running 10.3.4 (not the server version) ssh secure?
Since 10.3.4, if you "ask" for an ssh secure afp connection, you only get one if the server is running OSX Server, otherwise you get a warning that the connection is not secure (i.e. the afp server does not use ssh) so you know it can be "listened".
Is there a way to "make it work" even on the regular OSX? -
ssh secure AFP connection with OSX 10.3.4 (not server version) How To
2004-07-12 12:09:34 billpenn [Reply | View]
In order to AFP over an SSH tunnel , you first need to make an SSH tunnel and then you need to connect through that tunnel. I made a script to do this (I know it does no error checking, bad me). Here it is:
--Start Code--
#!/bin/sh
# script to make ssh tunnel and then connect to afp host
#
# Jan 02 2004 - W Penn - creation
#
LOCAL_PORT=10548;
LOCAL_HOST=127.0.0.1;
TARGET_PORT=548;
TARGET_HOST=xxx.xxx.xxx.xxx;
ssh -L $LOCAL_PORT:$TARGET_HOST:$TARGET_PORT -f -N $LOCAL_HOST;
open afp://localhost:$LOCAL_PORT/;
--end code--
You need to enter the host you want to connect to instead of "xxx.xxx.xxx.xxx" for the TARGET_HOST variable. You must be able to log in via afp, and remote login to TARGET_HOST.
When run depending on how your are authenticating to TARGET_HOST your remote login password may be requested, then the open command will bring up the afp login window directed to TARGET_HOST.
The script makes a secure/encrypted connection from the local machine to the TARGET_HOST's AFP port 548. Then the script tries to open an AFP connection over the secure connection. If you try to connect directly with connect to server please note that typing in the IP of your AFP server will not give you a secure connection even after opening the tunnel; instead, you must connect to the local end of the secure connection which from the script is localhost:10548. This is a little weird to the novice as you tell AFP to connect to the local machine in order to REALLY connect to your remote machine.
NOTE on firewalls: (1) you do NOT need to open up port 10548 on either machine. (2) You only need port 22 open in a non built in firewall between the two machines (like in a NAT router). (3) AFP and remote login must be turned on on the target in the sharing pref pane.
EXTRA NOTE: If you use this, you are using it because you are concerned about security, so you should not use it unless you understand what every - / ; a-z A-Z etc means.
You may find searching for "ssh tunnel" on mac OSX hints useful -
ssh secure AFP connection with OSX 10.3.4 (not server version) How To
2006-01-24 17:34:54 wfaulk [Reply | View]
This code is 100% insecure.
All it does is make a secure connection to the computer you're currently logged into (which is fairly pointless) and then opens an unencrypted tunnel to the remote host. The reason you can specify a host in the -L option is so that you can have an encrypted tunnel through an insecure network to one that is secure, but you can't open an SSH connection to the host you need to tunnel to, so you connect to another host on the remote secure network and it then passes the decrypted data to the other host. What you're doing here is encrypting the data between the localhost and itself, then passing unencrypted data to the remote host as if you'd never used SSH at all. All you're doing is wasting CPU cycles.
What you want to do is
ssh -L${LOCAL_PORT}:${TARGET_HOST}:${TARGET_PORT} ${TARGET_HOST}
This will open an encrypted channel to the remote host, where the data will be unencrypted and sent along to the host and port specified, which, in this case, is the same host doing the decrypting. -
ssh secure AFP connection with OSX 10.3.4 (not server version) How To
2004-07-13 05:57:08 Felix-fi [Reply | View]
May be I was too optimist... I could not get it to work... despite the fact that I can ssh to the server and AFP is running on it.
It seems to hang at the authentification stage...
Why do not you start the tunnel on the remote host? -
ssh secure AFP connection with OSX 10.3.4 (not server version) How To
2004-07-13 05:15:58 Felix-fi [Reply | View]
Thanks a lot. This solution would work indeed (I use it all the time to tunnel imap and smtp to the servers at work). I can see one drawback is that if you want to do that on more than one machine, you would need to use a new local port for each.
Still, I was wondering if there was a trick to reestablish the "server" ssh-afp feature on a non server OSX. (such as advertising a particular port on the afp server ;-) x being used for basic AFP and y for ssh-AFP)
Thanks again, -
ssh secure AFP connection with OSX 10.3.4 (not server version)
2004-07-11 08:26:40 FJ de Kermadec |
[Reply | View]
Hi !
I am afraid that I am not an AFP expert and that I cannot answer your question as well as I would like to.
However, could this document help you ?
http://docs.info.apple.com/article.html?artnum=25758
F.J. -
ssh secure AFP connection with OSX 10.3.4 (not server version)
2004-07-12 02:20:30 Felix-fi [Reply | View]
Thanks for the pointer... It does indeed explain how the client should behave (ask,force and require ssh) with respect to the AFP server... but does not explain how to reproduce the OSX Server capability on the "regulat" OSX version.
Thanks anyway,
-
Remote host has changed?
2004-07-09 17:45:38 ijak [Reply | View]
.
Hello,
I used to have this work when I was using Mac OSX 10.3.4 client. I have recently installed Mac OSX 10.3.4 Server on that same machine. ... Now when I try to connect, the terminal window starts to conect, then closes very fast. ... I did notice that there was writing in the window. I tried several times and eventually captured a SnapzPro image of the window. ...
What the window says is ...
----------------------------
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 RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote is
05:47;and a bunch more key stuff.
Please contact your System Administrator.
Add correct host key in Users/You/.ssh/known_hosts to get rid of this message.
---------------------------
I could do that, if I knew what to do. ...
What would be the propper thing to do in that known_hosts file?





