OPS145 Lab 8

From Littlesvr Wiki
Jump to navigation Jump to search

The server concept

For most people a server is something on the internet you connect to, and a client is something you connect from. That sort of view is mostly valid, but it breaks down a little when the server and the workstation are the same machine.

A couple of examples:

  • When you connect to wiki.littlesvr.ca in Firefox:
    • Firefox is the client, it's making the request for a web page
    • The web server (Apache) on wiki.littlesvr.ca is the server, responding the the request with the contents of the web page
  • When you use your phone to check your email:
    • The email application on your phone is the client, making the request to get new email
    • The email server (e.g. Postfix, Gmail, Office365) is the server, responding to the request with a list of new emails

Most of a Linux system administrator's work is done in a terminal, and most of that is done on remote machines. Few companies can afford to hire in-house administrators, and those that can afford it have too many machines to connect keyboards and monitors to. But everything is connected to a network.

The same client-server model applies here. You connect from a terminal on your workstation to the machine you want to work with. In this case:

  • The ssh program is the client, connecting to the ssh server, sends what you type to the server and prints the output which those commands print on the server.
  • The ssh server (sshd) is the software on the destination machine which receives commands from the client, executes them, and sends the output of those commands back to the client.

Temporary account on ops345.ca

I've created an account for you on ops345.ca which you can use for SSH practice.

You should have received an email like this:

OPS345NewAccountEmail.png

Note that your username has an ops145_ prefix. Your password is randomly generated.

Important.png
Please don't abuse this account
For example: don't upload 1GB videos to it. There are many students sharing this server, and I'm not an international corporation with money to burn. It's a single server on a relatively slow internet connection.

ssh to ops345.ca

You will be connecting to the ops345.ca server from your workstation using the ssh client.

The syntax for a basic ssh command is:

ssh usernameOnServer@serverAddress

The username is in your email. The server address is ops345.ca. After you run the ssh command: it will ask you for a password, which is the password in your email.

  • Go ahead and use ssh to connect to ops345.ca as ops145_yourusername

The first time you ssh to a server: the ssh client will give you a scary warning message about authenticity. It's a very interesting message which is worth understanding, but we don't have time to talk about it in this course. Just enter "yes" in the prompt.

FirstSSHtoops345.ca.png

From this point on anything you type at the terminal will be sent to the server you're SSHed to, the commands you run will be executed on the server, and the standard output/error they produce will be sent back to your terminal.

You can notice that:

  1. Your prompt is different. This is usually the first hint that you are SSHed to another machine.
  2. Your username is different.
  3. Your password is different.
  4. None of your files are in your home directory.
  5. There appear to be almost no files on this system at all (look in / and /bin)

Your account allows you to SSH into a chroot, which is another thing we don't have time to talk about.

  • You can end your session by running "exit"
  • Reconnect to ops345.ca and create a directory named lab8 inside your home directory.
  • On the server there is an /srv/art/ directory, with some ASCII art in text files. Copy that art directory and its contents into the lab8 directory you just created.
  • Use the cat command to look at the contents of the text files.
  • Change the permissions on the art directory to 700 so that noone else can read its contents.
  • You may look in other students' home directories under /home - the default permissions will allow you to do this. That's somewhat of a tradition from the old days.
  • If you like: change the permissions on your home directory so that other users cannot see what's in it.
Idea.png
You're working on a remote machine
It's important to understand that everything you've done in the ssh session is done on the remote machine. Open another terminal in your workstation and look for /home/ops145_yourusername, the lab8 directory you just created, or the ASCII art files. None of that stuff should be on your workstation.
  • Back in your terminal on ops345: create another directory named SampleFilesBackup under lab8. Leave that new directory empty for now.
  • Leave your ssh session running, but set this terminal window aside for a bit.

Copy files using scp

You can copy files from one Linux machine to another relatively easily.

The syntax for a basic scp command is a more complicated than the basic ssh command, but it's similar because scp uses an SSH tunnel to do its work:

scp fileOnLocalMachine usernameOnServer@serverAddress:destinationDirectory

The username, server, and password are the same as the ones you used with ssh. The fileOnLocalMachine is the name of the file you want to copy to the server. The destinationDirectory specifies which directory on the server you want to put the file into.

You can also copy files from the remote server to your local machine: just reverse the arguments.

  • In a terminal on your workstation: copy the file Snow.jpg from SampleFiles into your ~/lab8/SampleFilesBackup/ directory on the ops345 server:
    scp Snow.jpg ops145_yourusername@ops345.ca:~/lab8/SampleFilesBackup/
    
  • In your ssh session: confirm that the file has been copied. You can run ls -l to check that it has the same number of bytes on your workstation and on the server.
  • You can use copy more than one file at a time, and if you want: you can use wildcards. Copy both NotPlainText.odt and NotPlainText2.pdf from ~/Downloads/SampleFiles/ on your workstation to ~/lab8/SampleFilesBackup/ on ops345.ca:
    scp NotPlainText* ops145_yourusername@ops345.ca:~/lab8/SampleFilesBackup/
    
  • Copy both 1984.txt and AnimalFarm.txt from ~/Downloads/SampleFiles/ on your workstation to ~/lab8/SampleFilesBackup/ on ops345.ca. Note that both these files (and only these files in SampleFiles) end with .txt. So you can use the * wildcard to copy them both at the same time.

After you're done you should have at least these contents on the server:

ScpSomeFilesDone.png

Ownership

  • Run ls -l on the files you uploaded to the server.
  • Run ls -l on the same files on your workstation.

Note that everything you uploaded the server is owned by the username you logged in as after running the scp command. Your regular user from your workstation doesn't exist on the server.

Submit evidence of your work

After you finish the lab: run the following command to submit your work on the ops345.ca server:

ops145-lab8-check.sh

If it says "Your lab 8 has been submitted": make a screenshot, and you're done. If it gives you any warnings or errors: you have to fix them and try the ./ops145-lab5-check.sh command again.