Lab 1: Basic Usage of the CEE/CS Department Server
References:

The purpose of this lab is to learn how to use the command-line environment used for CMPS 2010 and 2020 assignments. You will learn how to login, logout, change your password, create a file, view files, and use the email client in this lab.

Read the entire contents of this page before beginning the lab work at the bottom of the page.

LAB 1 VIDEOS

The following videos walk you through the contents of Lab 1. You should read this page, then follow along on the videos to complete the work at the bottom of the page:

INTRODUCTION

The CEE/CS uses a Linux server as the programming environment for the CMPS 2010 and 2020 sequence. This server uses a text-based interface called a command-line interface (CLI). In a CLI, you type commands to accomplish tasks instead of clicking on icons. This course will introduce you to the basic commands you will need in the programming sequence.

The department server is called Odin. It is accessible over the Internet by using the domain name 'odin.cs.csub.edu' and an appropriate client to connect to Odin's CLI (called a terminal program). The terminal program will present you with a command-line prompt (such as the $ or > symbols). You can type commands at the prompt to initiate tasks.

Here are some examples of what a command-line prompt might look like (your prompt by default will look like the first two, but with your username before the @ symbol):

rowdyrunner@odin:~$
rowdyrunner@odin:~/2010$
(/home/stu/rowdyrunner/)>
(/home/stu/rowdyrunner/2010/)>

Typography Conventions

These typography conventions will be used throughout the lab to indicate how to properly create a command to type at the command-line prompt.

  • Items in fixed font are commands you should type in the terminal program to accomplish the task. Phrases after # or // are comments on the command and should NOT be typed.
    Example: man ssh // This gives the man page on the ssh command. You would just type man ssh for the command.
  • In a command, any phrase inside <angle-brackets> indicates a field that you MUST fill in for the command to work. When you give the field, you do NOT use angle-brackets, you just give the required item. For example, the phrase <filename> in the command less <filename> means you must give a filename for the less command to work, such as less lab1.cpp
  • In a command, any phrase inside [square-brackets] indicates an optional field that you can choose to use for the command. Again, when you give the field, you do not use the brackets. For example, the command ls -l [filename] can be correctly given as either ls -l or with a filename such as ls -l lab1.cpp
  • This lab will show you the basics of logging in and logging out, how to change your password, how to send and receive emails using a CLI email program, and how to create and view files.

    The second lab will show you how to manage file permissions, how to create and manage directories (folders), how to compile a program, and how to manage your processes (executables).

    The optional third lab will show you some more intermediate commands that can be used on the department server. It is STRONGLY recommended that students majoring in Computer Science or Computer Engineering review and complete this lab, but it is not required to get credit for this course. Even non-majors can find useful tips in this lab that can make their programming experience more efficient and enjoyable.

    HOW TO LOGIN AND LOGOUT

    You should have received an account sheet with your username and initial password for Odin at the start of the seminar. If you do not have an account sheet, see the instructor or a class assistant.

    To log in, you must connect over the Internet using the SSH protocol, which encrypts your Internet traffic so your data cannot be easily intercepted. You can log in from any place that has an SSH client and Internet connection. The department lab machines already have an SSH client installed, as do most of the campus computers in the basement of the library. You can also install an SSH client on your home machine or smart phone to connect to Odin from off campus.

    A popular program for Windows is Putty. You can download Putty from the department downloads page. Putty is a self-contained executable, which means it does not have to be installed. Just download it to a convenient location (such as your desktop) and click to launch it. Mac OS X should already have an SSH client installed which is very similar to the SSH client used on the department lab machines. There are no official recommendations for smart phone SSH clients at this time, but be sure to check reviews for any app that you are considering to be sure that the app is trusted before using it to login.

    To connect to Odin from the department Linux machines or Mac OS X, follow these instructions:

    1. Open the terminal application (the icon on the department lab machines that looks like a small, blank monitor or the Terminal program on Mac OS X).
    2. On the department machines, type the command ssh <username>@odin at the prompt. Enter your username in all lowercase and without the angle-brackets. From off campus or the campus wireless network, you will need to use the full domain name, so the command is ssh <username>@odin.cs.csub.edu
    3. Enter your password using uppercase and lowercase letters EXACTLY as given on your account sheet. Note that it is sometimes difficult to tell the difference between a lowercase L or the number 1 on the printout, so ask an assistant for help if the password does not seem to be working.

    Connecting from Putty on Windows is slightly different. Putty does not actually present you with a prompt to type the ssh command. Instead, it does the ssh command for you after you fill out a connection dialog entry. To connect from Putty on Windows, do the following:

    1. Double-click Putty to open it. This will bring up the connection dialog box for you to fill in.
    2. In the connection dialog box, set the Host Name (or IP address) field to: odin.cs.csub.edu
    3. In the connection dialog box, set the Protocol field to: ssh
    4. In the connection dialog box, verify that the Port field is 22. (Optional: once verified, you can save the connection information by typing a name for the connection in the lower saved session area and pressing Save)
    5. Press Open to establish the connection.
    6. Enter your account username in all lowercase exactly as given on the account sheet. DO NOT type the command ssh <username>@odin.cs.csub.edu. JUST give your username. You have already told Putty to do the SSH command to Odin when you filled out the connection dialog box, so you just need to give your username now. 7. Enter your password (case sensitive) as given on your account sheet or as you set it (if you opt to change your password later in this lab).

    Always make sure to logoff when you are done using the department server for the day. If you forget to logoff when you are using the department lab machines, the next student to use that machine can access your account, which means they can do anything to your account (including deleting all of your files). To logout, type the command

    exit
    Do NOT just click the x in the corner of the terminal program to close the terminal without first typing the exit command. If you close the terminal program while you are in the CLI email client, you might essentially lock yourself out of the email client. And if you close the terminal program while in the file editor, you will create a swap file that may or may not have the latest version of your program in it.

    Be safe: always logoff with the exit command.

    HOW TO PICK A SECURE PASSWORD

    The first command you will perform in this lab is to change your password from the default password to one you have chosen. You want a password you can remember and yet one that is secure. A secure password does not contain ANY word that can be looked up in a dictionary (hello99 is not secure), should contain at least one uppercase letter and one number (preferably, it would also include symbols like ! # = and so on), and should not be used for ANY of your other accounts.

    There are many ways to pick a secure password. One trick is the following: Pick a line in your favorite song or a well-known phrase. Take the first letters of every word in that line/phrase. Change one letter to a number and one letter to uppercase in a way that is easy to remember. For example,

    "the first noel the angels did say"
    
    becomes "t1ntAds" (where first is the number 1 and angels is capitalized). You now have a password that is easy to remember but difficult to crack.

    Another option is to go here: http://www.cs.csubak.edu/cgi-bin/passwordgen.cgi This utility will generate a secure and easy to remember password for you using a technique called "pronounceable passwords". Select one word from the list that you can easily remember. If you don't like any of the words, reload the page for a new list.

    You can also use a password vault program on your smart phone, but be aware that not all faculty members will let you use your smart phone in class, so if you create a long, random password that you can't remember without your phone, you might have problems.

    The command to change your password is

    passwd
    It will prompt you for your current password, which must be entered exactly. You will then be prompted to enter your new password twice. If the two entries do not match exactly (such as a typo), the command will fail and you will have to try again. If the command succeeds, it will just return you to the prompt without giving any message ("no news is good news").

    HOW TO ACCESS HELP FILES

    All the basic commands covered in this class have help files on them. These are called the "manpages" because they are associated with the man command. To start viewing a man page, give the following command:

    man <command>
    This will bring up one or more pages of information on the command. For multi-page information, use the space bar (or page down) key to go forward a page and the 'b' key (or page up) to go back a page. To exit the manpage viewer, hit the 'q' key.

    USING A TEXT EDITOR

    All of your programs for CMPS 2010 and 2020 will be created by writing a simple text file that contains your source code. The easiest way to do this is to issue a text editor command to start a text editor program. On Odin, the best text editor for creating your source code is the vi or vim (visual editor improved) text editor.

    This editor may seem a little intimidating at first, but it has many benefits, including color-coded syntax highlighting and automatic code indentation. All students are strongly encouraged to learn basic vi/vim commands. Students may also want to look into the intermediate vim commands given in the optional "intermediate commands" lab, as these can make the coding experience faster.

    The primary concept to grasp with vi/vim is the concept of modes. vi/vim has three main modes: insert mode, command mode and last-line mode. Insert mode is where you can add new content to the file, such as typing a new line of code. Command and last-line mode allow you to edit the file, such as deleting a word, saving the changes, and exiting vi/vim. All commands given in command mode execute as soon as you finish typing the command (without hitting enter). All last-line commands require you to hit enter for the command to execute. By default, vi/vim starts in command mode. Before you can make any changes, you have to enter insert mode. In order to save the changes, you have to leave insert mode and go back to command mode. Everyone should learn these basic commands as covered below:

    To start vi/vim, issue the following command (note that on Odin vi actually starts vim):

    vi <filename>
    Note: Filenames on Linux/UNIX do not have spaces in them, so make sure the filename is all letters, numbers and underscore characters.

    To enter into insert mode, hit the i key. You can then type what you wish to type and it will appear on the screen. You may also alter the contents of the file, such as deleting portions or using the arrow keys to navigate to another part of the file to alter it. Insert mode in vim works similarly to pico (but be aware in older systems the arrow keys will not work in insert mode). While you are in insert mode, the word '-- INSERT --' will appear at the bottom of your screen.

    To go back to command mode, hit the ESC key. Notice that the word '-- INSERT --' disappears, this indicates that you're back in command mode. If in doubt, hit ESC again. Think of the ESC key as your rescue button. If you can't remember what mode you are in, hit ESC. ESC will cancel any partial commands (but not any completed commands) and take you back to command mode. Anything you entered in insert mode will be preserved in vim's working buffer and will still be displayed on the screen.

    To undo the last change, go back to command mode and hit the u key. The last change is everything done in the last insert mode session or the last command executed while in command or last-line mode. To redo the last change, give the command CTRL-R from command mode. This is helpful when you accidently hit the u key instead of the i key.

    To save the file, go back to command mode and give the last-line command :w and hit the enter key. When you hit the colon key, a colon will appear at the very last line of your window. Then when you type w, it will appear at the bottom of the screen. Hit enter to execute the save command and the last line will be updated with information about the file.

    To exit vim, go back to command mode and give the last-line command :q and hit enter. This will return you to Odin's command-line prompt. This command will fail if there are any unsaved changes. If you accidently made changes and you want to quit WITHOUT saving the changes, give the last-line command :q! and hit enter.

    BASIC FILE MANIPULATION

    The next commands we will learn are for viewing and manipulating files (we'll learn about directories in the next lab). There will be a demonstration of these commands on the projector, so be sure to pay attention and follow along.

    The commands for file manipulation are:

    ls Lists all the files in your current directory
    ls -a [filename] Lists hidden files (filenames beginning with . are hidden, such as .bashrc)
    ls -l [filename] Gives detailed file information, such as size and permissions
    cat <filename> Prints the contents of a file with no paging (e.g. prints it all at once, even if the file is too big to display on your current screen size)
    less <filename> Prints the contents of a file with paging (like how the manpages display information)
    cp <source> <destination> Copies the source file to the destination file, leaving the source file intact (so you will have two copies of the file).
    mv <current_name> <new_name> Renames a file from the current filename to the new filename.
    rm <filename> Deletes a file. Note: there is NO undelete command, so be VERY SURE you want to delete a file before using this command.

    HOW TO USE ALPINE FOR EMAIL

    Your Odin email address is used by Computer Science faculty to communicate with you. You will also use your email account to submit assignments to the instructor. This is a full-fledged email account, so you can also use it to email anyone on the Internet. Odin is the primary email exchange server for the cs.csub.edu domain. Thus, your Odin email address is: <username>@cs.csub.edu

    The supported email client on Odin is alpine. Alpine is a text-only email client that works over X, telnet and ssh. Alpine also supports Internet protocols for mailing binary attachments (MIME). Like vi/vim, alpine uses commands. Unlike vi/vim, alpine commands are NOT case sensitive, so you can use the lowercase or uppercase letter for any command. When you first start alpine, you will be given a greeting message. Hit the E key to exit the greeting message.

    The most commonly used commands in alpine are:

  • C - Compose a new email message
  • L - List your mail folders
  • I - Go in to your inbox folder
  • M - Go to the main menu
  • Q - Quit alpine and go back to the prompt
  • Enter Key - Select the currently highlighted item
  • Arrow Keys - Move the cursor to highlight another item
  • , or < or Right Arrow Key - Go back one level (e.g. from an email back to your inbox)
  • To compose an email with an attachment, follow these steps:

    1. Hit the C key to enter the compose message screen.
    2. Enter the recipient's email address in the To: field.
    3. If you do NOT want to attach a file, go to step 8. Otherwise, to attach a file, hit CTRL-J (indicated as ^J in the alpine help listing at the bottom of the screen) to enter the attachment menu.
    4. Next hit CTRL-T to open the file browser.
    5. Use the arrow keys to highlight the file. If the file is in a directory, use the arrow keys to highlight the directory, then hit enter to go in to the directory.
    6. Once the file is highlighted, hit the enter key twice to attach it to the email message.
    7. Repeat steps 3 - 6 for each file you wish to attach.
    8. Arrow down to the Subject: field and enter a useful subject (if you are emailing an assignment to class, use the subject line your instructor told you to use). 9. Arrow down to the Message Text area and type your message. 10. When ready to send, hit CTRL-X and then Y to confirm. If you instead wish to throw away the email message WITHOUT sending it, hit CTRL-C and then C to confirm, and the message will be deleted.

    To read your new email, follow these steps:

    1. Hit the I key to go to your inbox.
    2. Use the arrow keys to highlight the message you wish to read.
    3. Hit the enter key to read the message.

    Read these instructions for more information on using alpine. There will also be a demonstration on the projector. You should practice sending emails to a student at a neighboring computer as you will be using alpine to submit your assignments in most CMPS 2010 sections.

    Alpine hint: If you are emailing another Odin user, you do not have to type their entire email address in the To: field. Just type their username and hit enter. If you have typed their username correctly, their full name will come up. This is a good habit to get into when submitting your assignments to make sure that you do not typo the instructor's name.

    WHAT TO COMPLETE FOR THIS LAB

    Now you are ready to perform the tasks below (It is assumed you have already logged into your account.) When you have successfully finished all items, and before logging out, ask a student assistant to check your terminal history to show that you have completed all of the following items. You will only receive credit by showing your work to a student assistant.

    1. Change your password (and make sure your new password is secure).
          passwd 
    2. List files in your current directory including hidden (dot) files.
          ls -al 
    3. Use vi to create a file called junk.txt.
          vi junk.txt 
    4. Go into insert mode in vi and add a few random lines to your junk.txt file.
          i
    5. Exit insert mode, then save the file and exit vi.
          ESC
          :w
          :q
    6. Copy junk.txt to a backup file called junk.bak.
          cp junk.txt junk.bak
    7. Rename the junk.txt file to stuff.txt.
          mv junk.txt stuff.txt 
    8. Dump the entire contents of the stuff.txt file to the screen.
          cat stuff.txt 
    9. Display the contents of the stuff.txt file one screen at a time using paging.
          less stuff.txt 
    10. Delete the stuff.txt file. Be very careful using the delete command since there is no undelete command.
          rm stuff.txt 
    11. Restore the junk.txt file by copying it from the backup file junk.bak.
          cp junk.bak junk.txt
    12. Use alpine to send an email with an attachment to your neighbor. Use the junk.txt file you created earlier in the lab as your attachment.
          alpine 
    Show your completed work to your CMPS 221 instructor or in-class tutor. If you are not currently in a CMPS 221 section, go to the Tutoring Center when it opens in Week 2 of the term to show a tutor your completed work.

    Once that is done, BE SURE TO LOGOUT (exit command).

    See you at the next lab!
    Download file viewer | CSUB - Computer Science Department