Stanford PSYCH 290

Natural Language Processing & Text-Based Machine Learning in the Social Sciences

We have sent you the IP of the class GCP server over Slack. And, for security reasons we will replace it with the string psych290_server here.

ssh <SUNetID>@psych290_server - Login to server psych290_server with your SUNetID as the username. The public-private key-pair is assumed to be in directory <home-directory>/.ssh.

From a user point of view, the server contains 2 services of importance to us - Jupyter and MySQL. And each listen to their respective ports.

SSH Port Forwarding for Jupyter

In macOS

ssh -L xxxx:localhost:xxxx <SUNetID>@psych290_server - creates a SSH tunnel that forwards all requests from local machine’s port xxxx to the server’s port xxxx . You can login to Jupyter using another token of the form 0cf2a5be4e71fffb1fa669035c0311b4ab2853a6c58c6287. Your respective port numbers and tokens are sent over Slack.

In Windows

Fire up PuTTY and enter the SUNetID>@psych290_server under Host Name or IP Address and 22 under Port. Then, go to Connection => SSH => Auth and import the private_key_windows.ppk to the Private key file for authentication section. Later, go to Connection => SSH => Auth => Tunnels and enter xxxx as the Source Port and localhost:xxxx as the Destination.

If you start Jupyter yourself from scratch (In 2021 we do this for you – but just so you know)

please pick your own 4-digit port that’s not 1234 or 3306 or 8888 or 8787, or use the one assigned to you

If you need an inspiration for a personal 4 digit number you can stick to:
1) Go to this website and enter the first 4 letters of your last name. You will get a 4 digit number.
2) Use that number as your port – replace xxxx with your 4 digit number everywhere where it says xxxx.

cmd description
ssh -L xxxx:localhost:xxxx <SUNetID>@psych290_server This creates a ssh tunnel that forwards all requests from local machine’s port xxxx to the server’s port xxxx.

Once inside the server, start Jupyter notebook session with:

cmd description
jupyter notebook --no-browser --port xxxx Starts Jupyter notebook session at port xxxx.

The above command will print:

[I 00:30:44.835 NotebookApp] JupyterLab extension loaded from /shared/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 00:30:44.836 NotebookApp] JupyterLab application directory is /shared/anaconda3/share/jupyter/lab
[I 00:30:44.871 NotebookApp] Serving notebooks from local directory: /home/ubuntu/psych290
[I 00:30:44.871 NotebookApp] The Jupyter Notebook is running at:
[I 00:30:44.871 NotebookApp] http://localhost:1234/?token=0cf2a5be4e71fffb1fa669035c0311b4ab2853a6c58c6287
[I 00:30:44.871 NotebookApp]  or http://127.0.0.1:xxxx/?token=0cf2a5be4e71fffb1fa669035c0311b4ab2853a6c58c6287
[I 00:30:44.871 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 00:30:44.873 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/ubuntu/.local/share/jupyter/runtime/nbserver-34596-open.html
    Or copy and paste one of these URLs:
        http://localhost:xxxx/?token=0cf2a5be4e71fffb1fa669035c0311b4ab2853a6c58c6287
     or http://127.0.0.1:xxxx/?token=0cf2a5be4e71fffb1fa669035c0311b4ab2853a6c58c6287

In your laptop/desktop browser, go to url http://localhost:xxxx/?token=0cf2a5be4e71fffb1fa669035c0311b4ab2853a6c58c6287.

SSH Port Forwarding for MySQL

Sequel Ace

cmd description
ssh -L 3306:localhost:3306 <SUNetID>@psych290_server This similarly creates a tunnel for MySQL, that forwards all requests from local machine’s port 3306 to the server’s port 3306.

You can then connect to the service using Sequel Ace where you enter Host as localhost or 127.0.0.1 , and User as your SUNetID. This will connect Sequel Ace to the local end of the tunnel we set up in SSH, from where it will travel through the interwebs, and then connect to port 3306 on the server.

HeidiSQL

Repeat the SSH Port Forwarding for Jupyter in Windows, but replace the occurences of xxxx with 3306. In HeidiSQL, choose MariaDB or MySQL (TCT/IP) for Network Type, localhost under Hostname/IP, and your SUNetID under User.

Some useful shell commands from the VTutorial Intro to Bash/Shell

cmd description
echo ‘hello world’ Prints the string ‘hello world’ to terminal.
pwd Prints current working directory.
cd Navigate to user home directory.
cd ~ Navigate to user home directory. The argument ‘~’ is assumed when cd is called without argument.
cd .. Navigate to parent(..) directory, unless this the root directory.
cd . Navigate to current(.) directory, which has no effect.
cd /path/to/some/directory Navigate to directory /path/to/some/directory.
ls List names of files/directories under current directory.
ls -a List names of files/directories under current directory, including the hidden files, which begin with dot(.).
ls -l List details of files/directories under current directory. Details include name, modification-date/time, size in bytes, owner, group and permissions.
ls -lh Same as ls -l but sizes are now printing in kilobytes(kb), megabytes(mb), gigabytes(gb) and so on.
echo ‘hello world’ > file.txt Command echo prints the string ‘hello world’ to terminal. The terminal then redirects this output to a file file.txt. Running this multiple times overwrites file.txt.
echo ‘hello world’ » file.txt Same as command with > except running multiple times appends to file.txt instead of overwriting it.
cat file.txt Print contents of file.txt to terminal.
mkdir dir1 Creates a directory dir1 in current directory.
mkdir /path/to/dir Creates a directory at location /path/to/dir.
cp file.txt file1.txt Copies file file.txt to another file file1.txt in the same directory.
cp /pathA/to/fileA.txt /pathB/to/fileB.txt Copies file /pathA/to/fileA.txt to another file /pathB/to/fileB.txt in a different directory.
cp -r dirA dirB Copies directory recursively from dirA to dirB in the same directory.
cp -r /pathA/to/dirA /pathB/to/dirB Copies directory recursively from /pathA/to/dirA to /pathB/to/dirB in a different directory.
mv file.txt file1.txt Moves file file.txt to another file file1.txt in the same directory. This is equivalent to renaming the file.
mv /pathA/to/fileA.txt /pathB/to/fileB.txt Moves file /pathA/to/fileA.txt to another file /pathB/to/fileB.txt in a different directory.
mv dirA dirB Moves directory from dirA to dirB in the same directory. This is equivalent to renaming the directory. Note the absence of -r compared to copy.
mv /pathA/to/dirA /pathB/to/dirB Moves directory from /pathA/to/dirA to /pathB/to/dirB in a different directory. Note the absence of -r compared to copy.
rm file.txt Delete file file.txt. There is no trash. It will be deleted forever.
rm -r dirA Delete directory dirA recursively. There is no trash. It will be deleted forever.