Dana Vrajitoru
C151 Multi-User Operating Systems

Lab 2

Date: Monday, February 8, 2021.

Ex. 1 a. X Client

For the first part of this lab you'll learn how to display a Linux application requiring a graphical user interface on any system. This will make things a lot more convenient for running some of the applications remotely, as it will allow you to use the mouse to interact with the window and the menus. What you need to run these applications is for your machine to work as an "X Client" for the host machine.

X or X11 is the basic library for displaying graphical interfaces on Linux, and an X client is a machine that knows how to interpret objects and functions from this library. Linux systems and any recent version of the MacOS have a native version of the X11 library. On Linux, this library is installed by default with the system, while on MacOS the library may have to be installed. On Windows, the library is not native, but an application can be installed to add an X extension to Putty and allow us to run X11 apps remotely.

Linux

If you work from a Linux computer in the CS labs, then there is nothing special to do.

If you work on a Linux computer from outside of the campus, you can either do the work locally, or connect remotely with the command explained in Lab 0 and in the file How To Connect. In the ssh command, the -X option specifies the use of the local X11 library. It is important for X to be uppercase.

If you get an error message when you try to open an application requiring a GUI, like gedit, then you may have to enable your local machine to accept the display of X applications from a remote location. For that, before you connect (you may have to close the connection, and open it again after this), run the command

xhost +

and then open the ssh connection with the -X option.

MacOS

If you work on an Apple computer, Mac OsX in any version prior to OsX 10.7... has X11 support. This means that by adding the option -XY to an ssh command, it should allow you to run any application needing a GUI remotely. This utility is normally installed with the system, but if it's not, you can look up the X11 on the Apple site and install it. The 6 computers in NS #209 feature such a system with X11 already installed.

On Mac OsX 10.7 and up, you need to install an X11 app or client, such as
http://xquartz.macosforge.org/landing/

You still need to set up a preference option that is useful when working remotely or even locally under X11. Go to the X11 menu at the top of the screen and open the Preferences... Click on the Input tab. Make sure that the third option about enabling key equivalents under X11 is not checked. Many X11 applications use the Ctrl and Cmd keys for their own purposes, and enabling the MacOS equivalents would disable the normal functionality of these keys under these applications. In the same window select "Emulate three button mouse". Go back to the terminal.

If you are working in the CS labs on one of the non-Linux machines, reboot the computer under MacOS (you have to hold the Alt key during the reboot to be able to choose the system).

Windows

If you work on a Windows machine, if you are working from one of the IT open labs computers, the software you need should already be installed: Putty and Xming. The version of Windows in NS #209 does not have Xming installed. You'll have to reboot on MacOS if you want to use those machines (or switch to a Linux computer).

At home, you will have to install an X client for Windows. The one that we have on campus and that I've tested myself with positive results is called Xming and you can download it from:
http://www.straightrunning.com/XmingNotes/ - click on the Xming link from Public Domain Releases.

Once you install it, you first have to start Xming. When asked to allow Xming to connect to networks, check both the private and public networks. Then open Putty normally and click (simple click) on one of your bookmarked links. Click on the button Load. Or simply type the name of the host instead. Before you click on Open, go to the Connection section on the left at the bottom, click on ssh, then on X11. Check the button Enable X11 forwarding. Now you can open the connection.

The steps to connect with an X-client are also summarized in the file How To X-client.

At the end of the session you'll have to export the content of the terminal as a text file. See How To Export Text for explanations.

b. Some GUI Applications

From the terminal where you established the connection as an X client, try the applications (and commands) gedit and firefox. They should both display under a new window with a GUI. You can close these windows once you see them working properly.

c. FTP

Let us establish an FTP connection to another computer. Go to your c151 folder (created in Lab 0 - or create one if you haven't in that lab). Create a folder called week2 and change your working directory to it. Then run the following command:

ftp ftp.gnu.org

The username should be anonymous. If a password is required, use an email address. The command establishes a file transfer protocol (or ftp) connection to this host machine. If the connection was established correctly, then you should see a different prompt on your command line (it looks like the greater sign).

Use the commands ls and cd to go to the directory non-gnu. Run the following command:

mget Free*

This command transfers multiple files based on the expression you use to identify them (Free* in this case) from the host machine to your local computer. The wild card has the same meaning as for the shell, identifying all the files starting with the letters Free.

Exit ftp with Ctrl-D or by typing exit or bye. Use ls to find out what file has been transferred, and then view the file with the command less (with the name of the file as argument) to view its content. You can follow-up the information in the file to find books using ftp and other resources (not part of the lab).

Note You can also use ftp from home to transfer files from your own computer to one of the machines in our labs or the other way around. In that case, use the command sftp instead. This is because our computers only accept secure ftp connections. Or if you use a GUI-based ftp program, such as WinSCP, make sure that the secure option is checked for the connection.

Next, let's use a terminal command to download an image file from the web. Run the following command:

wget http://www.cs.iusb.edu/~dvrajito/teach/c151/penguin.jpg

This command downloads a resource from a web URL and saves it in the working directory. This is a shortcut to using a browser.

d. Display

To see the image file downloaded above, run the command

display penguin.jpg

e. Network

Some more network commands

Ex. 2 Environment variables and links

Check the content of the environment variable HOME with the following command:

echo $HOME

Similarly, check the content of the variables USER, HOSTNAME, and PATH.

The last variable contains a list of paths separated by a colon (:). They identify folders where the shell can look for executable files when we run a command. Let us add the current directory to the path. We will add the symbol ./ identifying the current working directory (whichever that is when we're running any command), followed by the separator (:) and followed by the previous content of the variable path:

PATH="./:"$PATH

Echo the variable again to make sure that the . has been added to it correctly. Now to make sure that the path will be modified this way whenever you log on, edit a file called .bashrc directly in your home folder (it might not exist yet) and add the command above changing the value of the variable PATH to it. Save this file and exit the editor.

Let's create a symbolic link now. Go back to your home directory, create a link to the folder Documents, and call it docs. The command for that is

ln -s Documents docs

List the files in your directory with a long list of attributes. You should see this link listed with an l for the description on the left side and an arrow towards the Documents folder next to its name.

If you are working directly on a Linux computer (not through a remote connection), you can insert a CD in the CD drive or a flash drive in, wait until it mounts, then check in the folder /MEDIA or /media to see the name that it was mounted with. Then you can create a link to that whole path and call it cd if it's the CD drive, or usb if it's the flash drive (or whatever you want). It can make the operations with this mounted drive easier.

Canvas Upload

This is the end of the lab. Save the entire text of the lab to a file called lab2.txt. Upload this text file to Lab 2 under Assignments in Canvas.