Contents
This section describes how to configure a Virtual Computer Lab using GraphTerm on a Linux/Mac server. Some notable features are:
A companion section provides information on Using the GraphTerm Virtual Computer Lab after it has been set up. It can be printed and distributed to the users to serve as a quick start guide.
Note: The GraphTerm multiuser option is meant to be used for teaching purposes or for collaboration among trusted users. It should not be used if there is sensitive information on the server that should be protected from users.
The following steps allow you to quickly launch a “virtual computer lab” with multi-user support.
Install graphterm on your server using the following two commands:
sudo pip install graphterm
Omit the sudo if you are installing as a non-root user within an Anaconda or Enthought Python environment, for example.
Say all the user home directories begin with /Users..., then run the following command to start the GraphTerm server with root privileges:
sudo gtermserver --daemon=start --auth_type=multiuser --user_setup=manual --users_dir=/Users --logging --port=80 --host=server_domain_name_or_ip
To stop the server, use sudo gtermserver --daemon=stop. You can also omit the --daemon option, to run the server in the foreground for testing. To install GraphTerm as a service, you can copy the script $GTERM_DIR/bin/graphtermd to /etc/init.d and edit it to modify the command line options. If you want automatic new user creation, you can use the --user_setup=auto option, but you may need to modify the shell script $GTERM_DIR/bin/gterm_user_setup, which has only been tested with Ubuntu Linux.
- Run the following command as root user to display the master access code:
cat ~/.graphterm/@server_domain_name_gterm_auth.txt
(Ignore the port number following the hexadecimal access code.) If the domain name is localhost, the filename would simply be _gterm_auth.txt. For automatic new user creation, the group code is in ~/.graphterm/gterm_gcode.txt
- Use the URL http://server_domain_name to open a new graphterm window on the server, with the super user name (root in our case) and the master access code
Run the following command in the graphterm window to obtain the individual access code for each user:
gauth -m username
Distribute this code and a printed copy of Using the GraphTerm Virtual Computer Lab to each user. The first time an user enters their access code, the ~/.graphterm directory will be created, and there will be an option to enter the GMail address for authentication.
If you do not already have a Linux server available to set up a virtual computer lab, you can easily create one on demand using Amazon Web Services (AWS). The GraphTerm distribution includes the convenience scripts ec2launch, ec2list, ec2scp, and ec2ssh to launch and monitor AWS Elastic Computing Cloud (EC2) instances running a GraphTerm server. You will need to have an AWS account to use these scripts, and also need to install the boto python module. (These scripts are routinely used during GraphTerm development to test new versions in the “cloud”. )
You will need to obtain an AWS account as described here. The AWS account will be linked to your standard Amazon account.
Create an SSH key pair to access your AWS instances by clicking here. You need to name the key pair ec2key to be able to use the ec2ssh and ec2scp commands bundled with GraphTerm.
Install and run graphterm on your local (single-user) computer:
sudo pip install graphterm
gtermserver --terminal --auth_type=none
The above command should automatically open up a GraphTerm window in your browser. You can also open one using the URL http://localhost:8900 (Note: This is insecure on a shared, multi-user, computer; omit the --auth_type=none server option in that case.)
Run the following command within the graphterm window to create a Linux server:
ec2launch
The first time, you will be asked to enter your AWS access credentials, which will be stored in the local file ~/.boto. Then run the command again, enter a tagname (e.g., testlab), choose auth_type as multiuser, and select the pylab and netcdf options. When you press the submit button, the generated command line should look something like this:
ec2launch -f --type=m3.medium --key_name=ec2key --ami=ami-2f8f9246 --gmail_addr=user@gmail.com --auth_type=multiuser --pylab --netcdf testlab
After the new AWS Linux server has completed configuration, which can take several minutes, its IP address and server domain name will be displayed. If all went well, and you provided your GMail address, skip to Step 8.
If you are not using Google Authentication, or something went wrong with the AWS setup, type the following command using the new domain name to login to the password-less super user account ubuntu:
ec2ssh ubuntu@server_domain_name
Run the following command on the server to verify that gtermserver is running:
ps -ef | grep gtermserver
If not, and if using AWS, check for errors in the setup procedure by typing sudo tail /root/ec2launch.log
Run the following command on the server to display the master access code:
cat ~/.graphterm/@server_domain_name_gterm_auth.txt
(Ignore the port number following the hexadecimal access code.)
- Use the URL http://server_domain_name to open a new graphtem window on the server, with the super user name (ubuntu in our case) and using either Google Authentication or the master access code
Run the following command in the server graphterm window to display the group access code which should be entered by new users:
cat ~/.graphterm/gterm_gcode.txt
Distribute this code and a printed copy of Using the GraphTerm Virtual Computer Lab to all lab users.
If using AWS, run the following command on your local graphterm window to list and/or kill your instances:
ec2list
You can use the command gls --download $GTERM_DIR/bin/gterm.py to download the executable script gterm.py to your local computer and save the master access code in the local file ~/.graphterm/@server_domain_name_gterm_auth.txt. Then use the following local command to quickly create remote graphterm windows:
gterm.py -u ubuntu --browser=Firefox http://server_domain_name
After having set up the server, if you later decide to use your GMail account to authenticate, enter your GMail address in the file ~/.graphterm/gterm_email.txt on the server. (If you selected the gmail_addr option during ec2launch, this file would already have been created.)
Instead of AWS, if you wish to use a different cloud computing provider, you can either modify ec2launch or write your own script to configure the server. Running ec2launch with the --dry_run option displays the configuration steps for the Ubuntu Linux instances created using AWS. You may also need to modify the shell script $GTERM_DIR/bin/gterm_user_setup, which currently works with Ubuntu Linux on AWS.
Instead of using root to run the server, you could also use another account with password-less sudo privileges.
A server needs a domain name or IP address to be accessible. When you start up a new cloud server, it is usually assigned a dynamic IP address. For temporary use, i.e., during the up-time of the server, you can simply use this IP address to create an URL for the server like https://1.2.3.4:8900. AWS also provides a long instance domain name that can be used to create an URL.
For a prettier and more permanent URL, you need to register a domain name, say example.com, with a domain registrar like NameCheap.com, GoDaddy.com, or Gandi.net (for about $10-20 per year). A single domain registration is sufficient for any number of servers, as you can always create subdomains. For a single server, you can update the IP address associated with the domain on the nameservers of the registrar.
Alternatively, you can enable the Amazon Route 53 service Route 53 service and create a hosted zone for your domain example.com`. This will allow the ec2launch script to automatically assign subdomain names like sub.example.com to your servers. Ensure that the nameserver records for example.com at your domain registrar point to the AWS nameservers for the hosted zone.
The cloud server should be configured to allow access to certain network ports, particularly ports 22 (ssh), 80 (http), and 443 (https). If you plan to enable running of the “public” IPython notebook server, you should also allow access to the port range 10000-12000. The ec2launch script automatically sets up an AWS security group to allow access to these ports.
Note: If you have trouble accessing the instance, check to make sure that the AWS security group associated with the cloud instance allows access to inbound TCP port 22 (for SSH access).
To create an AWS instance, you should first run GraphTerm on your local (single-user) computer as described in the Quick setup instructions. You will be presented with a web form to enter configuration details of the instance to be launched. You can specify a simple tag name to identify each server. If you have set-up the Route 53 service, you can specify a the tag name is of the form subdomain.example.com to automatically associate the subdomain with the server IP address. You can also specify whether to install additional packages, like pylab for plotting or R for statistical analysis.
An important configuration choice is the authentication type (auth_type), which may be one of singleuser, none, name, or multiuser.
singleuser: Authentication type is meant for a single user on a shared computer. You will need to enter the code found in the file ~/.graphterm/_gterm_auth.txt to access the server, or use the gterm command to open new GraphTerm windows.
none: This requires no authentication, and is meant to be used on a private computer with a single user.
name: This also requires no authentication, but new users choose a unique username. This is meant for demonstration purposes and all users share the same Unix account.
multiuser: For the multiuser case, you typically specify either the --user_setup=auto or the --user_setup=manual option. The auto option allows new users enter enter a group authentication code, along with a unique user name. This creates a new Unix account for the user and generates a unique access code that will be used the next time the user logs in. The super user can view all the access codes using the gauth command. (If the users choose to use Google Authentication, they will also be able to login using their GMail account.) The --users_dir=/home option can be used to specify the root for all user home directories.
Once you fill in the form for ec2launch and submit it, a command line will be automatically generated, with the specified options, to launch the instance. You may need to wait several minutes for the instance setup to complete, depending upon the compute power of the instance. To launch another instance with slightly different properties, you can simply recall the command line from history and edit it. (If you wish to force re-display of the ec2launch form to edit the command visually, include the --form option in the recalled command line and execute it.)
The ec2list command can be used to list all running instances, and also to terminate them (using the kill link).
By default, a publicly accessible graphterm server will be automatically started on the new instance (and after reboots). Once the instance is running, you can access the GraphTerm server at http://domain_name_or_ip_address. You can log in to the instance using the command ec2ssh ubuntu@domain_name, or copy files to it using ec2scp file ubuntu@domain_name:
To stop a running server, type:
gtermserver --daemon=stop
If you are not using ec2launch, you can start the server explicitly from the command line, e.g.:
gtermserver --daemon=start --auth_type=multiuser --user_setup=auto --logging --nb_server --https --external_port=443 --host=domain_or_ip
The above options configure the server for multiuser authentication, with https. (ec2launch automatically configures port forwarding from port 443 to the default graphterm port 8900, enabling even non-privileged users to run gtermserver.)
An account with password-less sudo privileges is required for new users to be created automatically (--user_setup=auto option). Running an Ubuntu linux instance on AWS automatically creates such an account, named ubuntu, as described here. By default, GraphTerm server is run from this account. The --user_setup=auto option creates a file named ~/.graphterm/AUTO_ADD_USERS which can be deleted to suppress auto-user creation while the server is running.
To automatically start the server when the computer is rebooted, copy the gtermserver command line to the executable script /etc/init.d/graphterm on a Ubuntu server followed by update-rc.d graphterm defaults, or equivalent for other linux flavors (ec2launch automatically does this for AWS).
The master access code is stored in the file ~/.graphterm/@server_gterm_auth.txt in the home directory of the super user, and can be used to sign in as any user. (To generate new random access codes, simply delete this file.) To display the access code for a particular user, use the following command within a GraphTerm on the remore machine:
gauth -m username
The user-specific access code is also save in the user’s home directory in ~user/.graphterm/user@server_gterm_auth.txt.
To avoid having to type in the access code every time, you can download the executable python script $GTERM_DIR/bin/gterm.py to your desktop/laptop computer. You can then type the following command:
gterm.py -u user http://server_domain
to open a terminal on the remote server. You will be asked for the access code the first time, and then it can be saved in your local ~/.graphterm directory for future use.
To display the group access code (needed to generate new accounts), type:
gauth -g -m super_username
on the server.
You can run the gtermserver with the --https option enabled for limited security. By default, it will create a self-signed certificate stored in ~/.graphterm/localhost.pem. Inform users that self-signed certificates will generate multiple browser warning messages. (For maximum security, you can purchase a domain certificate signed by an authority, which is often available through the domain registrar.)
Specifying the --nb_server when starting up the GraphTerm server enables a menu option allowing each user to run to run the the gnbserver command which starts up a public IPython Notebook server listening on a unique port number that is tied to the user’s Unix user ID. (A similar option for ec2launch opens up these ports for public access.)
If using https, the self-signed certificate created for the GraphTerm server can be re-used for the IPython public notebook server, by copying the file ~/.graphterm/localhost.pem to /var/graphterm/localhost.pem to make it accessible to all users.
The super user can use the shell script gterm_user_setup in $GTERM_DIR/bin to manually configure new users:
sudo gterm_user_setup username activate server_domain user_email
Note: This script may need to be modified to work on non-AWS servers.
The gadmin command (a work in progress) performs administrative actions to monitor users:
# Display status for all terminals with path name matching python regexp
gadmin -a sessions [regexp]
Clicking on the displayed terminal list will open up the terminal for viewing (see Dashboard for a “virtual computer lab” - listing user terminal activity).
You can also view multiple user terminals embedded in your own terminal using the gframe command (see Dashboard for a “virtual computer lab” - viewing user terminals):
gframe --rowheight 300 --border --columns 3 --terminal /bob/quiz1 /jane/quiz1 /jose/quiz1
In the multiuser authentication mode, user groups can be configured the file ~/.graphterm/gterm_groups.json containing a JSON formatted dictionary, e.g.:
{"group1": ["user1", "user2"],
"group2": ["user3", "user4", "user5"]}
Users in the same group can see each others’ terminals for collaboration.
Secondary cloud instances can connect to the GraphTerm server on the primary instance using the command:
gtermhost --daemon=start --server_addr=<server_domain_or_address> <secondary_host_name>
Note: It would be better to use an internal (non-public) network address to connect secondary cloud instances.