The CS2030S Programming Environment
Java version
Java is a language that continues to evolve. A new version is released every six months. For CS2030S, we will only use Java 11, the second most recent version with long-term support1. Specifically, we use openlogic-openjdk-11.0.8+10
on Ubuntu 20.04.3 LTS.
Programming Servers
The school has provided a list of computing servers for you to use, with all the required software for CS2030S installed. You can access them remotely via ssh
, or secure shell. The hosts are named pe111
, pe112
, ... , pe120
. (pe
stands for "programming environment"). We will refer to these servers generally as the PE hosts.
For this semester, the two servers pe115
and pe116
are not available.
You can choose which of the eight hosts to use. You share the same home directory across all the hosts (this home directory, however, is different from that of stu1
). If you notice that one host is crowded, you can use another host to spread out the load.
While you can complete the programming assignments on your computers, the practical exams are done in a controlled environment using servers similar to the PE hosts. It is therefore advisable for you to familiarize yourself with accessing the PE servers via ssh
and edit your program with either vim
or emacs
(vim
is recommended and supported).
Accessing CS2030S Programming Environment
Basic Requirements
-
You should be familiar with the terms Unix, command-line interface, command prompt, terminal, and shell. Read this background article if you don't.
-
You need to have an SoC Unix account. If you do not have one, you can apply for one online.
-
Once you have an account, you need to activate your access to the PE hosts, which is part of the SoC computer clusters.
-
You need a command-line
ssh
client. Windows 10, macOS, and Linux users should already have it installed by default.For older versions of Windows, such as those used in the SoC's programming labs, you can check out XShell 6 (free for home/school use), or PuTTY. These are GUI-based programs so the command line instructions below do not apply.
-
You need a good terminal app. There are many choices, but we recommend Windows Terminal for Microsoft Windows users; the default Terminal or iTerm2 for macOS users.
Testing Your SoC Unix Account
You can skip this step if you have been using your SoC Unix account and is familiar with your SoC Unix username and password.
-
Launch the terminal app on your computer.
-
At the command prompt, connect to SoC Unix server
stu.comp.nus.edu.sg
with the secure shellssh
. The basic command tossh
is
1 |
|
Replace <hostname>
with the host you want to log into and <username>
with your SoC Unix username. Note that both are case-sensitive.
For instance, I would do:
1 |
|
stu.comp.nus.edu.sg
.
After the command above, follow the instructions on the screen. The first time you ever connect to a host, you will be warned that you are connecting to a previously unknown host.
1 2 3 4 |
|
Say yes
, and you will be prompted with your password for that host. Type in your SoC Unix password. Note that passwords are case-sensitive, and nothing will be shown on the screen as you type your password for security reasons. Press Enter when you are done. You should see something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
If you have reached this step, your SoC Unix username and password are working.
Type Ctrl D to exit before continuing with the next step.
Accessing The PE Hosts
This is the step that you need throughout the semester to access the PE hosts.
The PE hosts can only be accessed from within the School of Computing networks. This is not an issue during your lab sessions, but if you wish to access the PE hosts from outside of SoC, you need to tunnel through stu.comp.nus.edu.sg
.
The server (stu.comp.nus.edu.sg
) is configured to allow your connection if it's originating from a local telco (See more details here).
Since stu.comp.nus.edu.sg
is within the SoC network, you can log into stu.comp.nus.edu.sg
first, then from stu.comp.nus.edu.sg
, log into one of the PE nodes. These two steps can be done with one command:
1 |
|
- In non-exam scenarios, replace
username1
andusername2
with your SoC Unix username andpe1xx
with one ofpe111
tope120
. You will be prompted for your password twice. The first prompt will be for your password tostu.comp.nus.edu.sg
, and the second, tope1xx.comp.nus.edu.sg
. Again, in a non-exam scenario, they will both be your SoC Unix password. - For practical exams, you will be issued a special exam account to log into the PE hosts. In this case,
username1
will be your SoC Unix username andusername2
will be your special exam account.
You should see something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
This means you have successfully connected to the CS2030S programming environment.
You can now proceed to do three things:
- learn about the basic Unix commands to navigate your home directory and manipulate files.
- learn about how to edit a file in
vim
, by running the commandvimtutor
. A CS2030S vim guide is also available. - set up password-less login to the PE hosts
Troubleshooting
If you get the following error:
-
ssh: Could not resolve hostname pe1xx.comp.nus.edu.sg
ssh
cannot recognize the namepe1xx
. Likely, you tried to connect to the PE hosts directly from outside of the SoC network. -
Connection closed by 192.168.48.xxx port 22
You have connected to the PE host, but you are kicked out because you have no permission to use the host.
Make sure you have activated your access to "SoC computer clusters" here
-
Permission denied, please try again
You did not enter the correct password or username. Please use the username and password of your SoC Unix account which you have created here: https://mysoc.nus.edu.sg/~newacct/.
Check that you have entered your username correctly. It is case-sensitive.
If you have lost your password, go here: https://mysoc.nus.edu.sg/~myacct/iforgot.cgi
-
ssh: connect to host stu.comp.nus.edu.sg port 22: Operation timed out
It means that you failed to connect to
stu.comp.nus.edu.sg
viassh
. There could be two reasons for this: (i)stu.comp.nus.edu.sg
or its ssh service is down; (ii) you are connecting via a network wherestu.comp.nus.edu.sg
is not accessible (such as outside Singapore).The likelihood of (i) is small. The more likely scenario is (ii). In either case, connect to SoC VPN first, then
ssh
into one of the PE host. -
Could not chdir to home directory /home/o/ooiwt: Permission denied
This error means that you have successfully connected to the PE hosts, but you have no access to your home directory.
This should not happen. Please send an email with the above error message to
helpdesk@comp.nus.edu.sg
, include the PE hosts that you connected to with this error and your username. The system administrator can reset the permission of your home directory for you.
Setting up Password-less Login
To avoid typing in your password repeatedly, you can change the way you authenticate yourself to stu.comp.nus.edu.sg
and the PE hosts, from using a password to using public-key cryptography for authentication. The keys come in pairs: a public key and a private key. The private key must be kept safe and known only to you. You should keep the private key in your account, and not share it with others.
To authenticate yourself to another host or service, you configure the host/service with your public key. When it is time for you to log in, your private key is "matched"2 with your public key. Since only you know your private key, the service or the host can be sure that you are you and not someone else.
The following is a one-time setup to enable this.
Let's say you want to log in from Host A to Host B. On Host A, run:
1 |
|
to generate a pair of keys on Host A. When prompted, you can save the file id_rsa
in the default location ~/.ssh
and enter an empty passphrase.
Expanded What the command above does is it creates two files, the private key id_rsa
and the public key id_rsa.pub
. Next, you need to plant the public key on Host B. There are two ways to do this:
Method 1: Using ssh-copy-id
If Host A has ssh-copy-id
installed, then, on Host A, run:
1 |
|
You will be prompted to enter your password for Host B. After this step is completed, your public key will be copied to and configured for password-less login to Host B.
Method 2: Manually copy the public key to Host B.
First, you need to copy the public key id_rsa.pub to your home directory on the remote host you want to log into. We will use scp
, or secure copy, for this. On Host A,
1 |
|
You will be prompted with your password to login to transfer the file.
Then, log into the Host B, run,
1 |
|
to add your public key to the list of keys.
Make sure that the permission for .ssh
on Host A and Host B are set to 700 and the files id_rsa
on Host A and authorized_keys
on Host B are set to 600. See the ls
and chmod
After using either one of the methods above, you should be able to ssh
into Host B without using being prompted for a password every time.
Recall that to log in to a PE host, you need to two steps, first from your local computer to into stu.comp.nus.edu.sg
, then from stu.comp.nus.edu.sg
into pe1xx.comp.nus.edu.sg
. So to setup password-less login to pe1xx.comp.nus.edu.sg
, you need two steps.
For example, using Method 1 (ssh-copy-id
), you need to do the following.
First, on your local computer:
1 2 |
|
Then, on stu.comp.nus.edu.sg
:
1 2 |
|
Since all the PE hosts share the same file directory, you only need to do this for one of the PE hosts. After this one-time step, you can log in without a password to any one of the PE hosts.
Stability of Network Connections
Note that a stable network connection is required to use the PE hosts for a long period without interruption. If you encounter frequent disconnections while working at home or on campus while connected wirelessly, please make sure that your WiFi signal is strong and there is no interference from other sources.
If you find yourself facing frequent disconnection, you can consider running screen
. After logging into a PE host, run:
1 |
|
You will see some messages, press Enter to go to the command prompt. You can now use the PE host as usual. In case you are disconnected (e.g., in the middle of editing), you can log into the same PE host again, and run:
1 |
|
to resume your previous session.