Skip to content

Commit fe1b75e

Browse files
committed
add remote computing chapter
1 parent 3f39d97 commit fe1b75e

File tree

9 files changed

+420
-8
lines changed

9 files changed

+420
-8
lines changed

book/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/

book/_quarto.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ website:
2525
- section: "Course information"
2626
contents:
2727
- href: index.qmd
28+
- href: modules/setup.qmd
2829
- section: "Contents"
2930
contents:
3031
- href: modules/module1.qmd

book/_variables.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site:
2+
localprompt: '`[you@laptop:~]$`'
3+
remoteprompt: '`[yourUsername@login1 ~]$`'
4+
anyprompt: '`$`'

book/modules/module1.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 01 - The Bash shell
33
subtitle: Introducing to linux command line
4-
time: "0:30"
4+
time: "0:00"
55
execute:
66
cache: true
77
freeze: true

book/modules/module3.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 03 - Creating and editing files
33
subtitle: Folder and file manipulations and text editors
4-
time: "0:50"
4+
time: "1:00"
55
execute:
66
cache: true
77
freeze: true

book/modules/module4.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 04 - Pipes and Filters
33
subtitle: Linking commands together
4-
time: "0:35"
4+
time: "1:50"
55
execute:
66
cache: true
77
freeze: true

book/modules/module5.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 05 - Scripts and variables
33
subtitle: Automating workflows
4-
time: "0:50"
4+
time: "2:30"
55
execute:
66
cache: true
77
freeze: true

book/modules/module6.qmd

+191-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,203 @@
11
---
22
title: 06 - SSH and SCP
33
subtitle: Logging in to remote computers and data transfer
4-
time: "0:15"
4+
time: "3:20"
55
execute:
66
cache: true
77
freeze: true
8-
8+
custom-callout:
9+
answer:
10+
icon-symbol: "📝"
11+
color: "teal"
12+
title: "Solution (Click to Expand)"
13+
collapse: true
14+
filters:
15+
- custom-callout
916
---
1017

11-
Welcome to chapter 2!
18+
HPC systems (supercomputers, computer clusters, virtual machines in the cloud) are 'remote' resources that we connect to over the internet. There are various ways to connect to a remote machine, and in recent years web portals have become available for this purpose. `ssh` is the traditional way to connect to a remote machine from the command line, and it is still very practical to use `ssh` for various reasons such as data transfer, automation of workflows, and more flexibility and control over the remote machine. And if you are fluent in using the command line, then it is generally faster to work with the command line than the graphical user interface.
19+
20+
SSH stands for Secure SHell protocol, and is used to open an encrypted network connection between two machines, allowing you to send & receive text and data without having to worry about prying eyes.
21+
22+
![](https://carpentries-incubator.github.io/hpc-intro/fig/connect-to-remote.svg)
23+
24+
This mechanism consists of a key on your own home computer, and a key on the computer you wish to connect to. They form a set (although they are by no means identical) and as such a login attempt can be validated. The key on your own computer from which you wish to connect to a remote system is the private key, and you should not share this with anyone. The key on the remote system is the public key, and you can use it for multiple purposes/platforms as you wish (e.g. a compute cluster, a virtual machine in the cloud, GitHub).
25+
26+
:::{.callout-warning title="Private keys are your secure digital passport"}
27+
28+
A private key that is visible to anyone should be considered compromised, and must be destroyed. This includes having improper permissions on the directory it (or a copy) is stored in, traversing any network that is not secure (encrypted), attachment on unencrypted email, and even displaying the key on your terminal window.
29+
30+
Protect this key as if it unlocks your front door. In many ways, it does.
31+
:::
32+
33+
The Lesson Setup provides instructions for creating ssh keys. If you have not done so already, please setup the keys now.
34+
35+
## Log in to a remote machine
36+
37+
38+
log in to the
39+
cluster. Replace `<your username>` with your username and `<ip address>` with the one supplied by the instructors.
40+
41+
```bash
42+
ssh <your username>@<ip address>
43+
```
44+
45+
You may be asked for your password. Watch out: the characters you type after
46+
the password prompt are not displayed on the screen. Normal output will resume
47+
once you press `Enter`.
48+
49+
You may have noticed that the prompt changed when you logged into the remote
50+
system using the terminal
51+
52+
This change is important because
53+
it can help you distinguish on which system the commands you type will be run
54+
when you pass them into the terminal. This change is also a small complication
55+
that we will need to navigate throughout the workshop. Exactly what is displayed
56+
as the prompt (which conventionally ends in `$`) in the terminal when it is
57+
connected to the local system and the remote system will typically be different
58+
for every user. We still need to indicate which system we are entering commands
59+
on though so we will adopt the following convention:
60+
61+
* {{< var site.localprompt >}} when the command is to be entered on a terminal
62+
connected to your local computer
63+
* {{< var site.remoteprompt >}} when the command is to be entered on a
64+
terminal connected to the remote system
65+
* `$` when it really doesn't matter which system the terminal is connected to.
66+
67+
## Looking Around Your Remote Home
68+
69+
Very often, many users are tempted to think of a high-performance computing
70+
installation as one giant, magical machine. Sometimes, people will assume that
71+
the computer they've logged onto is the entire computing cluster. So what's
72+
really happening? What computer have we logged on to? The name of the current
73+
computer we are logged onto can be checked with the `hostname` command. (You
74+
may also notice that the current hostname is also part of our prompt!)
75+
76+
```bash
77+
{{< var site.remoteprompt >}} hostname
78+
```
79+
80+
```output
81+
login1
82+
```
83+
84+
So, we're definitely on the remote machine. Next, let's find out where we are
85+
by running `pwd` to **p**rint the **w**orking **d**irectory.
86+
87+
```bash
88+
{{< var site.remoteprompt >}} pwd
89+
```
90+
91+
```output
92+
/home/yourUsername
93+
```
94+
95+
96+
Great, we know where we are! Let's see what's in our current directory:
97+
98+
```bash
99+
{{< var site.remoteprompt >}} ls
100+
```
101+
102+
## Data transfer
103+
104+
There are 2 main options to get data to your remote system:
105+
106+
- Downloading data that is somewhere on the internet
107+
- Uploading data from your laptop
108+
109+
### Downloading data
110+
111+
If the code or data that you need has a URL, you can use the `wget` or `curl` command to download (one or both of these commands are usually installed in most Linux based systems).
112+
113+
```bash
114+
wget -O new_name https://some/link/to/a/file
115+
curl -o new_name https://some/link/to/a/file
116+
```
117+
118+
:::{.exercise}
119+
::::{.exercise-header}
120+
Download using `wget` and `curl`
121+
::::
122+
::::{.exercise-container}
123+
Try to download the workshop material of this workshop on the remote machine. The material is available via this url: `https://swcarpentry.github.io/shell-novice/data/shell-lesson-data.zip`
124+
125+
:::{.answer}
126+
```bash
127+
wget -O workshop-material.zip https://swcarpentry.github.io/shell-novice/data/shell-lesson-data.zip
128+
```
129+
:::
130+
::::
131+
:::
132+
133+
Assuming Git is installed on the remote system, you can clone repositories as follows:
134+
135+
```bash
136+
git clone https://github.com/UtrechtUniversity/workshop-introduction-to-bash.git
137+
```
138+
139+
Datasets that are stored on e.g. SURFdrive or Yoda can be downloaded using tools that (if they are not available already) can be installed. `rclone` for SURFdrive and `ibridges` or `icommands` for Yoda. Manuals can be found [here](https://utrechtuniversity.github.io/vre-docs/docs/manuals.html).
140+
141+
### Uploading data
142+
143+
## scp
144+
When you work on a Windows machine and you use MobaXterm for SSH connection, you can use the file browser in MobaXterm to intuitively transfer data.
145+
146+
In all other cases: Open a terminal (or shell session) that you use for login in to your workspace via the `ssh` command.
147+
148+
```
149+
scp sourcefile <username>@<ip-address>:destinationdir
150+
```
151+
152+
You can find both the username and the ip-address in the [research cloud portal](https://portal.live.surfresearchcloud.nl/).
153+
Find your username under the 'Profile' tab.
154+
Find the IP address of your workspace in the main Dashboard by clicking the drop down arrow of the running Workspace.
155+
156+
```
157+
scp testfile.txt <username>@<ip-address>:data/storage/input_data
158+
```
159+
If you first need to create a destination folder where you want to transfer the data to:
160+
161+
```
162+
ssh <username>@<ip-address>
163+
mkdir ~/data/storage/input_data
164+
logout
165+
scp testfile.txt <username>@<ip-address>:data/storage/input_data
166+
```
167+
168+
To transfer a directory add the `-r` option:
169+
170+
```
171+
scp -r sourcedir <username>@<ip-address>:data/storage/input_data
172+
```
173+
174+
## rsync
175+
176+
Rsync is a tool for synchronizing two folders. This method can also be used to transfer the contents of a folder to a remote folder. You typically run this tool on your own PC in the [terminal](../manuals/terminal.qmd) (so e.g.before login in using the `ssh` command, or in a separate terminal (or shell session)).
177+
178+
Type `rsync --help` on to see if it is installed on your system. To install:
179+
180+
### Install
181+
182+
On Debian based linux (e.g. Ubuntu):
183+
184+
```
185+
sudo apt-get install rsync
186+
```
187+
188+
On mac:
189+
```
190+
brew install rsync
191+
```
12192

193+
### Usage
13194

14-
## Exercises
195+
```
196+
rsync -azP ./my_local_folder <username>@<ip-address>:my_destination_folder
197+
```
15198

199+
```
200+
rsync -azP ./my_local_folder <username>@<ip-address>:~/data/storage/input_data
201+
```
16202

203+
Where `-azP` are options. Type `rsync --help` to see a list of the options.

0 commit comments

Comments
 (0)