Lecture 6: SSH, SCP, Mail, Networking Tools

Knoppix

Demo of starting Knoppix

To use Knoppix in the lab, find it in Program Files, then click on the .vbox file. None of the stuff you do here is persistent, so save all your work on Matrix.

Live USB

There are many distros for Linux, some of them are very niche. You can try any of these out without affecting your system configuration. Search for ‘Live USB Creator’, and you will many options for creating a Live USB. From here, you can reboot your computer, boot from the USB drive (you may need to change your BIOS settings to enable this), and follow the instructions. This can often be a simple solution if you aren’t used to setting up virtual machines.

What distro to choose? Here are a few of the common ones:

Whatever you choose, you will still have many configuration options available to you. A Desktop Environment, for example, changes how your GUI looks. Ubuntu and Fedora both use GNOME 3, and as a result they look pretty similar by default. But you can easily play with Cinnamon, Plasma, Budgie, XFCE, etc.

SSH

Now that we are in Knoppix, I can show you how we would use our SSH command:

ssh <user>@matrix.senecacollege.ca

If this was my persistent system, I might generate a key-pair and then copy a public key to Matrix.

What is SSH? It stands for Secure SHell. In the past, we might have used a program like Telnet to log into our machine. Telnet is old, and insecure. At this point there is no reason to use it. With SSH, everything between your remote and local machine is encrypted. You can even use SSH as a ‘tunnel’, and manipulate programs with GUIs using SSH.

SCP

Another important command to learn is SCP, which uses SSH for file transfers. Just like our cp command, we need to give it a target and a destination. The difference is that one or both of these paths is going to be remote, and so we need to provide more information.

scp <target> <destination>

So let’s say our target is remote, and our destination is local. I’m going to choose ‘frankenstein.txt’ as my target. I have access to my own account, so this should work.

scp eric.brauer@matrix.senecacollege.ca:~/frankenstein.txt ~

The syntax of the first argument is important. username@hostname:filepath. If you ever get confused, follow the same syntax you see on your command prompt.

eric@eric-eriga:~/uli/courseNotes$ – don’t include the $!

To transfer an entire directory, you will need the -r option! Let’s push a directory from Knoppix, rather than pulling a file this time.

scp -r /tmp eric.brauer@matrix.senecacollege.ca:~

Let’s take a look…

Mail

If you go through the process of setting up mail on your system, you can send mail from the command line. More importantly, any scripts that you write can send out mail if your server encounters a problem.

mail recipent@hostname, then enter subject and body of message. Or:

mail recipient@hostname -s "Subject" < body-of-mail

You can also send mail to other users on Matrix:

mail recipient@localhost

SFTP

FTP is a protocol used for downloading files. It isn’t secure by default, so it’s been replaced by SFTP. SFTP uses SSL encryption.

sftp user@host: to log in.

ls, pwd, etc: to navigate remotely.

!ls, !pwd, etc.: to navigate locally.

get filename, put filename: to pull and push files.

Ctrl_d: exits.

Other Networking Tools

Networking is something we sadly don’t cover enough of in this course. But here’s a quick crash course.

ip address: Returns important information like your… ip address.

netstat: Among other things, you can use it to see open ports on your system.

nslookup matrix.senecacollege.ca: Returns IP from URL, and URL from IP address.

ping matrix.senecacollege.ca: Ping is still the simplest way to start network troubleshooting.

wget <url>: So whenever you have a link to file to download from a website, this command will download it to your current location. This is different from scp, because you don’t need any kind of credentials and you also can’t expect any encryption. But it’s useful if, say, you need to grab a driver or document online and you have the URL handy.

curl: There are many ways to use curl, and too much to cover. But basically you can use it like wget, or to return HTTP assets. Or test a RESTful interface.

If you’d like to really dive into using curl, check out this post by Julia Evans.


Introduction to Vim

Whenever you want to edit text files and the job requires more than just echo, you will probably have a couple of options.

For quick simple jobs, try using nano. For more complex jobs, try using vim.

You’ll see references to both vi and vim. Vim stands for v(im)proved. Both are available to you on Matrix.

Vim is an extremely powerful text editor that can years to master. Some developers love Vim above and beyond all other IDEs and text editors. Everyone else will struggle to exit Vim…

vim memes exist, you guys.
vim memes exist, you guys.

As part of Assignment #1, you are required to finish the Vim tutorial, which honestly does a very good job of showing you the basics.

In Vim, there are three important modes:

Another important option is turning on line numbers. Try entering command mode again and type set number.

I recommend using a tool such as vimtutor to get more comfortable with the basics.

Vim is a necessary tool when all else fails, and you should try to get a basic understanding of it. You certainly don’t have to love it, though! In addition, keep in mind that there are no questions about Vim on tests/quizzes.


Summary

BONUS: Making SSH Painless

“How do you log into Matrix so quickly?”

If you’ve noticed, I can log into Matrix by typing ssh matrix. There’s two parts to this:

First of all, I have an alias set up. This means that matrix == eric.brauer@matrix.senecac.on.ca. There are a couple ways to do this, but here’s one: In your home directory, there is a hidden directory called .ssh. You can create a file in .ssh called config.

cat ~/.ssh/config

host matrix
    hostname matrix.senecacollege.ca
    user eric.brauer

Be sure to test this by typing in ssh matrix and making sure that you get prompted for your password.

Now you can work on the next part, which is generating a private/public key pair. On Linux this is easy:

ssh-keygen

You will be prompted to set a location. Press Enter to accept the default. You will also be prompted to enter a passphrase, but that’s optional.

Once you generate the keypair, you will need to transfer your public key to Matrix. The command to do this:

ssh-copy-id matrix

If you checked your config file before, this should work. You will be prompted for your password for the last time..! Be sure to keep your private key secure, but now you should be able to log in much quicker.

Making SSH Painless with PuTTY

Putty will require a few more steps, including installing a separate program. Keep in mind that you will need to specify a safe location for your private key! These instructions should be more or less complete, but don’t attempt this if you have a looming deadline.

Generating an SSH key in PuTTY