If you are running a POSIX-compatible system, most of the coding you’ll be asked to do this semester should work fine on your own machine. If not, you should have a department account which will allow you to access remote servers either via SSH (as described in this document) or via remote desktop (via NoMachine).
1 Use SSH without passwords
Typing passwords is both less secure (key-sniffers, typos, typing wrong passwords, etc) and more tedious than using a private key.
1.1 Concept
You’ll place a file on your computer and a file on the remote computer. They are matched, and each provides half of the work needed to do a job. When you log in, the remote computer will do half the work with its file, then send that to your computer to do the other half, then send it back, thus allowing both computers to be confident the other computer is who it says it is1.
1.2 Setup
The following commands should work on any system with SSH installed2,
ssh-keygen -f ~/.ssh/id_rsa -t rsa -b 2048
When prompted for a passphrase by ssh-keygen
, just press
enter without typing anything. Once ssh-keygen
is done,
type the following3 with appropriate changes to
username@the.server.edu
:
ssh-copy-id -i ~/.ssh/id_rsa.pub username@the.server.edu
When prompted for a passphrase by ssh-copy-id
, use your
UVA CS account password.
2 Edit local, compile remote
You can edit files on your own machine and send them to the servers just for compiling and running.
You should put each program in its own folder in this course.
- To push files from your computer to the servers
-
Open the terminal or command prompt your operating system supports
Change to the directory of your code
Run
scp * mst3k@portal.cs.virginia.edu:code/project/directory/
, where*
meansall files in the current directory
mst3k
is your computing IDcode/project/directory/
is the path to the directory on the department servers where your code will live. You may have to create this directory on the department servers first.
- To run commands remotely
-
Open the terminal or command prompt your operating system supports
Run
ssh mst3k@portal.cs.virginia.edu "the command you want to run on the server"
, wheremst3k
is your computing IDthe command you want to run on the server
is a valid linux command, which may be several commands separated by;
For example, you might do something like
"cd coa2/warmup; make"
You can even put all of this in a makefile, as e.g.
.PHONY: remote
remote:
scp * mst3k@portal.cs.virginia.edu:code/project/directory/"cd code/project/directory/; make" ssh mst3k@portal.cs.virginia.edu
This is a gross over-simplification, but gets the core idea across. We’ll see what’s really going on when we discuss digital certificates↩︎
If on Windows, you also may need to use
\
instead of/
(whether you do or not depends on which command line tool you use).There is a slight chance that
~/.ssh
will not already exist. In that casessh-keygen
will fail; if you see such a failure you can fix it by runningmkdir ~/.ssh chmod 700 ~/.ssh
and then re-run the above commands↩︎
ssh-copy-id
is simple enough, some distributions of OpenSSL don’t include it. If you don’t have it, trycat "~/.ssh/id_rsa.pub" | ssh username@portal.cs.virginia.edu "cat >> .ssh/authorized_keys"
On Windows, you might need to use
type
instead ofcat
:
↩︎type "~/.ssh/id_rsa.pub" | ssh username@portal.cs.virginia.edu "cat >> .ssh/authorized_keys"