Skip to content

Commit

Permalink
Further refactoring to seperate out SSH, the protocol, from ssh and
Browse files Browse the repository at this point in the history
 scp, the client programs
  • Loading branch information
Kevin M. Buckley committed Jul 11, 2015
1 parent a266982 commit 5204c67
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
29 changes: 19 additions & 10 deletions 02-ssh.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,27 @@ <h2 id="learning-objectives" class="objectives panel panel-warning"><span class=
<li>Learn what an SSH key is</li>
<li>Generate your own SSH key pair</li>
<li>Learn how to use your SSH key</li>
<li>Learn how to work remotely using ssh and scp</li>
<li>Learn how to work remotely using <code>ssh</code> and <code>scp</code></li>
<li>Add your SSH key to an remote server</li>
</ul>
</div>
</div>
<p>Let’s take a closer look at what happens when we use the shell on a desktop or laptop computer. The first step is to log in so that the operating system knows who we are and what we’re allowed to do. We do this by typing our username and password; the operating system checks those values against its records, and if they match, runs a shell for us.</p>
<p>As we type commands, the 1’s and 0’s that represent the characters we’re typing are sent from the keyboard to the shell. The shell displays those characters on the screen to represent what we type, and then, if what we typed was a command, the shell executes it and displays its output (if any).</p>
<p>What if we want to run some commands on another machine, such as the server in the basement that manages our database of experimental results? To do this, we have to first log in to that machine. We call this a <a href="./reference.html#remote-login">remote login</a>, and the other computer a remote computer. Once we do this, everything we type is passed to a shell running on the remote computer. That shell runs those commands on our behalf, just as a local shell would, then sends back output for our computer to display.</p>
<p>The tool we use to log in remotely is the <a href="./reference.html#secure-shell">secure shell</a>, or SSH. In particular, the command <code>ssh username@computer</code> runs SSH and connects to the remote computer we have specified. After we log in, we can use the remote shell to use the remote computer’s files and directories. Typing <code>exit</code> or Control-D terminates the remote shell and returns us to our previous shell.</p>
<p>What if we want to run some commands on another machine, such as the server in the basement that manages our database of experimental results? To do this, we have to first log in to that machine. We call this a <a href="./reference.html#remote-login">remote login</a>.</p>
<p>In order for us to be able to login, the remote computer must be runing a <a href="./reference.html#remote-login-server">remote login server</a> and we will run a client program that can talk to that server. The client program passes our login credentials to the remote login server and, if we are allowed to login, that server then runs a shell for us on the remote computer.</p>
<p>Once our local client is connected to the remote server, everything we type into the client is passed on, by the server, to the shell running on the remote computer. That remote shell runs those commands on our behalf, just as a local shell would, then sends back output, via the server, to our client, for our computer to display.</p>
<h3 id="ssh-history">SSH History</h3>
<p>Back in the day, when everyone trusted each other and knew every chip in their computer by its first name, people didn’t encrypt anything except the most sensitive information when sending it over a network and the two programs used for running a shell (usually back then, the Bourne Shell, <code>sh</code>) on, or copying files to, a remote machine were named <code>rsh</code> and <code>rcp</code>, respectively. Think (<code>r</code>)emote <code>sh</code> and <code>cp</code></p>
<p>However, anyone could watch the unencrypted network traffic, which meant that villains could steal usernames and passwords, and use them for all manner of nefarious purposes.</p>
<p>The <a href="./reference.html#ssh-protocol">SSH protocol</a> was invented to prevent this (or at least slow it down). It uses several sophisticated, and heavily tested, encryption protocols to ensure that outsiders can’t see what’s in the messages going back and forth between different computers.</p>
<p>The remote login server which accepts connections from client programs is known as the <a href="./reference.html#ssh-daemon">SSH daemon</a>, or <code>sshd</code>.</p>
<p>The client program we use to login remotely is the <a href="./reference.html#secure-shell">secure shell</a>, or <code>ssh</code>, think (<code>s</code>)ecure <code>sh</code>.</p>
<p>The <code>ssh</code> login client has a companion program called <code>scp</code>, think (<code>s</code>)ecure <code>cp</code>, which allows us to copy files to or from a remote computer using the same kind of encrypted connection.</p>
<h3 id="a-remote-login-using-ssh">A remote login using <code>ssh</code></h3>
<p>To make a remote login, we issue the command <code>ssh username@computer</code> which tries to make a connection to the SSH daemon running on the remote computer we have specified.</p>
<p>After we log in, we can use the remote shell to use the remote computer’s files and directories.</p>
<p>Typing <code>exit</code> or Control-D terminates the remote shell, and the local client program, and returns us to our previous shell.</p>
<p>In the example below, the remote machine’s command prompt is <code>moon&gt;</code> instead of just <code>$</code>. To make it clearer which machine is doing what, we’ll indent the commands sent to the remote machine and their output.</p>
<pre class="input"><code>$ pwd</code></pre>
<pre class="output"><code>/users/vlad</code></pre>
Expand All @@ -61,11 +73,7 @@ <h2 id="learning-objectives" class="objectives panel panel-warning"><span class=
<pre class="input"><code> moon&gt; exit</code></pre>
<pre class="input"><code>$ pwd</code></pre>
<pre class="output"><code>/users/vlad</code></pre>
<h3 id="ssh-history">SSH History</h3>
<p>Back in the day, when everyone trusted each other and knew every chip in their computer by its first name, people didn’t encrypt anything except the most sensitive information when sending it over a network and the two programs used for running a shell (usually back then, the Bourne Shell, <code>sh</code>) on, or copying files to, a remote machine were named <code>rsh</code> and <code>rcp</code>, respectively. Think (<code>r</code>)emote <code>sh</code> and <code>cp</code></p>
<p>However, anyone could watch the unencrypted network traffic, which meant that villains could steal usernames and passwords, and use them for all manner of nefarious purposes.</p>
<p>SSH was invented to prevent this (or at least slow it down). It uses several sophisticated, and heavily tested, encryption protocols to ensure that outsiders can’t see what’s in the messages going back and forth between different computers.</p>
<p>The “secure” version of <code>rsh</code>, called <code>ssh</code>, think (<code>s</code>)ecure <code>sh</code>, has a companion program, (<code>s</code>)ecure <code>cp</code>, called <code>scp</code>, which allows us to copy files to or from a remote computer using the same kind of encrypted connection as SSH.</p>
<h3 id="copying-files-to-and-from-a-remote-machine-using-scp">Copying files to, and from a remote machine using <code>scp</code></h3>
<p>To copy a file, we specify the source and destination paths, either of which may include computer names. If we leave out a computer name, <code>scp</code> assumes we mean the machine we’re running on. For example, this command copies our latest results to the backup server in the basement, printing out its progress as it does so:</p>
<pre class="input"><code>$ scp results.dat vlad@backupserver:backups/results-2011-11-11.dat
Password: ********</code></pre>
Expand All @@ -85,12 +93,13 @@ <h3 id="ssh-history">SSH History</h3>
results-2011-10-04.dat 100% 9 1.0 MB/s 00:00
results-2011-10-28.dat 100% 8 1.0 MB/s 00:00
results-2011-11-11.dat 100% 9 1.0 MB/s 00:00</code></pre>
<p>Here’s one more thing SSH can do for us. Suppose we want to check whether we have already created the file <code>backups/results-2011-11-12.dat</code> on the backup server. Instead of logging in and then typing <code>ls</code>, we could do this:</p>
<h3 id="running-commands-on-a-remote-machine-using-ssh">Running commands on a remote machine using <code>ssh</code></h3>
<p>Here’s one more thing the <code>ssh</code> client program can do for us. Suppose we want to check whether we have already created the file <code>backups/results-2011-11-12.dat</code> on the backup server. Instead of logging in and then typing <code>ls</code>, we could do this:</p>
<pre class="input"><code>$ ssh vlad@backupserver &quot;ls results*&quot;
Password: ********</code></pre>
<pre class="output"><code>results-2011-09-18.dat results-2011-10-28.dat
results-2011-10-04.dat results-2011-11-11.dat</code></pre>
<p>SSH takes the argument after our remote username and passes them to the shell on the remote computer. (We have to put quotes around it to make it look like a single argument.) Since those arguments are a legal command, the remote shell runs <code>ls results</code> for us and sends the output back to our local shell for display.</p>
<p>Here, <code>ssh</code> takes the argument after our remote username and passes them to the shell on the remote computer. (We have to put quotes around it to make it look like a single argument.) Since those arguments are a legal command, the remote shell runs <code>ls results</code> for us and sends the output back to our local shell for display.</p>
<h3 id="ssh-keys">SSH Keys</h3>
<p>Typing our password over and over again is annoying, especially if the commands we want to run remotely are in a loop. To remove the need to do this, we can create an <a href="./reference.html#ssh-key">SSH key</a> to tell the remote machine that it should always trust us.</p>
<p>SSH keys come in pairs, a public key that gets shared with services like GitHub, and a private key that is stored only on your computer. If the keys match, you’re granted access.</p>
Expand Down
85 changes: 53 additions & 32 deletions 02-ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title: Working Remotely
> * Learn what an SSH key is
> * Generate your own SSH key pair
> * Learn how to use your SSH key
> * Learn how to work remotely using 'ssh' and 'scp'
> * Learn how to work remotely using `ssh` and `scp`
> * Add your SSH key to an remote server
Let's take a closer look at what happens when we use the shell
Expand All @@ -31,22 +31,58 @@ What if we want to run some commands on another machine,
such as the server in the basement that manages our database of experimental results?
To do this,
we have to first log in to that machine.
We call this a [remote login](./reference.html#remote-login),
and the other computer a remote computer.
Once we do this,
everything we type is passed to a shell running on the remote computer.
That shell runs those commands on our behalf,
We call this a [remote login](./reference.html#remote-login).

In order for us to be able to login, the remote computer must be runing
a [remote login server](./reference.html#remote-login-server) and we will
run a client program that can talk to that server.
The client program passes our login credentials to the remote login server
and, if we are allowed to login, that server then runs a shell for us on the
remote computer.

Once our local client is connected to the remote server,
everything we type into the client is passed on, by the server, to the shell
running on the remote computer.
That remote shell runs those commands on our behalf,
just as a local shell would,
then sends back output for our computer to display.
then sends back output, via the server, to our client, for our computer to display.

### SSH History

Back in the day,
when everyone trusted each other and knew every chip in their computer by its first name,
people didn't encrypt anything except the most sensitive information when sending it over a network
and the two programs used for running a shell (usually back then, the Bourne Shell, `sh`) on, or copying
files to, a remote machine were named `rsh` and `rcp`, respectively. Think (`r`)emote `sh` and `cp`

However, anyone could watch the unencrypted network traffic, which meant that villains could
steal usernames and passwords,
and use them for all manner of nefarious purposes.

The [SSH protocol](./reference.html#ssh-protocol) was invented to prevent this (or at least slow it down).
It uses several sophisticated, and heavily tested, encryption protocols
to ensure that outsiders can't see what's in the messages
going back and forth between different computers.

The remote login server which accepts connections from client programs is known as the [SSH daemon](./reference.html#ssh-daemon), or `sshd`.

The client program we use to login remotely is the [secure shell](./reference.html#secure-shell),
or `ssh`, think (`s`)ecure `sh`.

The `ssh` login client has a companion program called `scp`, think (`s`)ecure `cp`,
which allows us to copy files to or from a remote computer using the same kind of encrypted connection.


### A remote login using `ssh`

To make a remote login, we issue the command `ssh username@computer`
which tries to make a connection to the SSH daemon running on the remote computer we have specified.

The tool we use to log in remotely is the [secure shell](./reference.html#secure-shell),
or SSH.
In particular, the command `ssh username@computer`
runs SSH and connects to the remote computer we have specified.
After we log in,
we can use the remote shell to use the remote computer's files and directories.

Typing `exit` or Control-D
terminates the remote shell and returns us to our previous shell.
terminates the remote shell, and the local client program, and returns us to our previous shell.

In the example below,
the remote machine's command prompt is `moon>`
Expand Down Expand Up @@ -94,25 +130,8 @@ $ pwd
/users/vlad
~~~

### SSH History

Back in the day,
when everyone trusted each other and knew every chip in their computer by its first name,
people didn't encrypt anything except the most sensitive information when sending it over a network
and the two programs used for running a shell (usually back then, the Bourne Shell, `sh`) on, or copying
files to, a remote machine were named `rsh` and `rcp`, respectively. Think (`r`)emote `sh` and `cp`

However, anyone could watch the unencrypted network traffic, which meant that villains could
steal usernames and passwords,
and use them for all manner of nefarious purposes.

SSH was invented to prevent this (or at least slow it down).
It uses several sophisticated, and heavily tested, encryption protocols
to ensure that outsiders can't see what's in the messages
going back and forth between different computers.

The "secure" version of `rsh`, called `ssh`, think (`s`)ecure `sh`, has a companion program, (`s`)ecure `cp`, called `scp`,
which allows us to copy files to or from a remote computer using the same kind of encrypted connection as SSH.
### Copying files to, and from a remote machine using `scp`

To copy a file,
we specify the source and destination paths,
Expand Down Expand Up @@ -176,7 +195,9 @@ results-2011-10-28.dat 100% 8 1.0 MB/s 00:00
results-2011-11-11.dat 100% 9 1.0 MB/s 00:00
~~~

Here's one more thing SSH can do for us.
### Running commands on a remote machine using `ssh`

Here's one more thing the `ssh` client program can do for us.
Suppose we want to check whether we have already created the file
`backups/results-2011-11-12.dat` on the backup server.
Instead of logging in and then typing `ls`,
Expand All @@ -191,7 +212,7 @@ results-2011-09-18.dat results-2011-10-28.dat
results-2011-10-04.dat results-2011-11-11.dat
~~~

SSH takes the argument after our remote username
Here, `ssh` takes the argument after our remote username
and passes them to the shell on the remote computer.
(We have to put quotes around it to make it look like a single argument.)
Since those arguments are a legal command,
Expand Down

0 comments on commit 5204c67

Please sign in to comment.