README.md 7.1 KB
Newer Older
Sergio Coronado's avatar
title    
Sergio Coronado committed
1
# Linux Basics 101 and GitLab R3 Workshop
Sergio Coronado's avatar
Sergio Coronado committed
2

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
3
4
5
6
7
8
9
## Quiz (to get to know you)

* Who doesn't know what an IP address is?
* Who doesn't know what a server is?
* Who doesn't know what a port is?


Sergio Coronado's avatar
Sergio Coronado committed
10
11
## How to connect to a remote Session
***
Sergio Coronado's avatar
Sergio Coronado committed
12

Christophe Trefois's avatar
Christophe Trefois committed
13
14
15
16
17
18
19
### 1. My terminal is better than yours?

> Definition: A terminal is an interface in which you can type and execute text based commands.

#### Download your Terminal if you don't have one already.


Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
20
+ **Windows**
Christophe Trefois's avatar
Christophe Trefois committed
21
  + MobaXterm [download](http://mobaxterm.mobatek.net/download-home-edition.html)
Christophe Trefois's avatar
Christophe Trefois committed
22
23

  > Remarks: In Windows, there is a default command line, called command prompt. However, the names of many commands is different and some commands do not exist. For that reason, use another terminal, such as MobaXterm.
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
24

Christophe Trefois's avatar
Christophe Trefois committed
25
+ **Mac**
Christophe Trefois's avatar
Christophe Trefois committed
26
27
  + iTerm2 [download](https://www.iterm2.com/downloads.html)
  + Terminal
Christophe Trefois's avatar
Christophe Trefois committed
28
+ **Linux**
Christophe Trefois's avatar
Christophe Trefois committed
29
30
31
  + Terminal

### 2. Generate your SSH key
Christophe Trefois's avatar
Christophe Trefois committed
32
33
34

#### Background information

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
35
+ **What is SSH?**
Christophe Trefois's avatar
Christophe Trefois committed
36
37
38

<img src="images/screen3.png" width=600>

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
39
* **What is a SSH key pair?**
Christophe Trefois's avatar
Christophe Trefois committed
40

Christophe Trefois's avatar
Christophe Trefois committed
41
42
<img src="images/screen4.jpg" width=400>

Christophe Trefois's avatar
Christophe Trefois committed
43
44
#### Key generation

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
45
+ **Windows (MobaXterm) / Mac / Linux**
Christophe Trefois's avatar
Christophe Trefois committed
46
47
  + ssh-keygen

48
        ```bash
49
50
51
52
53
54
55
56
57
        vagrant@vagrant-ubuntu-trusty-64:~$ ssh-keygen
        Generating public/private rsa key pair.
        Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
        Enter passphrase (empty for no passphrase):
        Enter same passphrase again:
        Your identification has been saved in /home/vagrant/.ssh/id_rsa.
        Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
        The key fingerprint is:
        ac:d7:36:ee:74:f6:34:d1:ff:ee:dd:bc:d5:ee:70:36 vagrant@vagrant-ubuntu-trusty-64
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
58
        The key\'s randomart image is:
59
60
61
62
63
64
65
66
67
68
69
        +--[ RSA 2048]----+
        |                 |
        |                 |
        |                 |
        |       .       . |
        |        S     . .|
        |       . .     .o|
        |      . . = o +E*|
        |       . + + o B*|
        |         .o   .=@|
        +-----------------+
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
70
        ```
Christophe Trefois's avatar
Christophe Trefois committed
71

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
72
73
  > Note, you must **NEVER** share the id_rsa file with anybody

Christophe Trefois's avatar
Christophe Trefois committed
74
75
76
### 3. Create LUMS account

This task has been done already by your awesome R3 team.
Christophe Trefois's avatar
Christophe Trefois committed
77

Christophe Trefois's avatar
Christophe Trefois committed
78
### 4. Add SSH key to LUMS (**L**CSB **U**ser **M**anagement **S**ystem)
Christophe Trefois's avatar
Christophe Trefois committed
79

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
80
81
* Attach your *public* SSH key to your LUMS account
* To get the contents of your public key, type the following command (you will understand it all later today :) )
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
82

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
83
84
85
86
```bash
cd
cat .ssh/id_rsa.pub
```
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
87

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
88
Expected output (your key will be different)
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
89

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
90
Question: Is it OK for me to post my public key publicly?
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
91

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
92
93
94
```
christophe.trefois.TrefexVMPC$ cd && cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRVvaaZejn/CHQsXdb2nMzzPP3WF14H9djaTWmOCabl/q1BJEjWX21P1D+r45mB1EUfUi5w1VrN6I3/9ytZweOa4kLsMJCYU0sEwZq2KKOEKkW7M7W6LGJ+4C2QzkXLCY4r2yToAK7HwvvDUoDF3Ioodw9omTFLaHGzTLEsw9KVrYYwcyAQ5SOQTsL3VuMgyTd+Z8414HPIQrB3abEqHGGvkcrxnKhaEF/R3NNJ523ErRmRZa9cIB6dhXjzEIcvgaDzMKtXbflciVt3u3vM+4aaKhHwO73KUv8wDiPau8ROxmvNkADZB4gpsjbKqVP876QCT5YI5Z0D8Bcj5GoKZ1D christophe.trefois@TrefexVMPC
Christophe Trefois's avatar
Christophe Trefois committed
95

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
96
```
Christophe Trefois's avatar
Christophe Trefois committed
97

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
98
99
* Go to https://lcsb-ipa.uni.lu
* Login with first.lastname and password linuxwork2015
Christophe Trefois's avatar
Christophe Trefois committed
100

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
101
    > (Note: Use your password for existing LUMS account)
Christophe Trefois's avatar
Christophe Trefois committed
102

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
103
104
105
106
* Next to SSH public keys, click on Add and copy paste the key in there, including `ssh-rsa` and the text at the end.

* Don't forget to click on *Update* on the top menu buttons.

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
107
108
109
### 5. Connecting to Virtual Machine

* **Windows / Mac / Linux**
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
110
111
  * Open your terminal
  * Connect to the workshop virtual machine
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
112

Christophe Trefois's avatar
Updates    
Christophe Trefois committed
113
        ```bash
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
114
        ssh first.lastname@10.79.2.191 -p 8022
Christophe Trefois's avatar
Updates    
Christophe Trefois committed
115
        ```
Sergio Coronado's avatar
Sergio Coronado committed
116

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
117
118
119
120
121
122
123
      Explanations:

      * `ssh` is the command we will use to connect to our server
      * `first.lastname` is the username we will use
      * `@10.79.2.191` is the IP address of the server itself
      * `-p 8022` is a parameter. Here it specifies the port to connect to.

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
124
125
126
127
## Before we start

* A word that looks like `this` means that you should replace the word `this` with appropriate content.

Sergio Coronado's avatar
Sergio Coronado committed
128
129
## Discover your surroundings
***
Sergio Coronado's avatar
Sergio Coronado committed
130
131
* In which folder am I? (Hint: pwd)
* What is the contents of the current folder? (Hint: ls)
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
132
133
* Creating my first file called myFile.txt (Hint: touch `filename`)
* Checking that my file exists (Hint: ls)
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
134
* Creating my first folder called "myFirstFolder" (Hint: mkdir `foldername`)
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
* How do I enter my new folder? (Hint: cd `foldername`)
* Copying my first file to the new folder (Hint: cp `source` `target`)

**Exercise 1**

Check if the file is in the correct folder.

    Hint: ls, pwd

What if I want to see a structure like in Windows Explorer?

--> Try this:

```bash
cd
tree
```

You should see something like this:

```bash
.
├── myFile.txt
└── myFirstFolder
    └── myFile.txt

1 directory, 2 files
```

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
164
**Exercise 2**
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
165

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
166
I see `myFile.txt` twice. Maybe I should remove the copy I don't want.
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
167
168
169
170

* Go to where the to-be-deleted file is (Hint: cd)
* Remove the file (Hint: rm -i `myFile.txt`)

Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
171
> In Linux, when asked questions you usually type `y` for **Yes** and `n` for **No** unless explicitly written.
Sergio Coronado's avatar
Sergio Coronado committed
172

Christophe Trefois's avatar
Christophe Trefois committed
173
174
175
176
177
## A couple remarks on file / folder names
* Try not to use spaces
* Try to capitalize some words for easier reading
  * for instance: thislongfoldernameisnotveryreadable, but ThisLongFolderNameIsQuiteReadable

Christophe Trefois's avatar
Christophe Trefois committed
178
## Learn more about any *nix command
Sergio Coronado's avatar
Sergio Coronado committed
179
***
Sergio Coronado's avatar
Sergio Coronado committed
180
181
* Go to your home folder (Hint: cd <no arguments>)
* Are there any hidden files in my home folder? (Hint: man ls)
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
182
183
184
185
186

> A hidden fie or folder starts with a dot. Note, on Windows, you normally can't create folders that start with a dot but with mobaXterm you can :)

When you do `ls -al` you see a different view and many hidden files.

Sergio Coronado's avatar
Sergio Coronado committed
187
* How do I get such nice documentation for other unix commands? (Hint: man <mycommand>)
Sergio Coronado's avatar
Sergio Coronado committed
188
189
190

## Copy files to the VM or from the VM (only using console!!)
***
Sergio Coronado's avatar
Sergio Coronado committed
191
* Logout of the VM (Hint: logout)
Christophe Trefois's avatar
Fixes    
Christophe Trefois committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
* Create a local training folder `training` (Hint: mkdir `training`)
* Go to the new folder called `training` (Hint: cd)
* Create a new file on your computer (Hint: touch `file3.txt`)
* Copy file1.txt to “myFirstFolder” on the VM

  Hint:

  ```bash
  scp –P 8022 first.lastname@1079.2.191:/myFirstFolder/
  ```

  Explanations:

  * `scp` stands for `secure copy`
  * `-P 8022` specifies the port on which the server is accpeting our connection
  * `first.lastname@10.79.2.191` specifies how we want to login
  * `:/myFirstFolder` means the file will be put in to that folder on the server
Sergio Coronado's avatar
Sergio Coronado committed
209
210
211

## Start a simple program:
***
Sergio Coronado's avatar
Sergio Coronado committed
212
* Intro to command, parameters
Christophe Trefois's avatar
Christophe Trefois committed
213
* How to zip my folder? Unzip?
Sergio Coronado's avatar
Sergio Coronado committed
214
* wget -> untar -> changes -> re-pack
Sergio Coronado's avatar
Sergio Coronado committed
215

Christophe Trefois's avatar
Christophe Trefois committed
216
## Text editor
Sergio Coronado's avatar
Sergio Coronado committed
217
***
Sergio Coronado's avatar
Sergio Coronado committed
218
* nano [Tutorial](http://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/)
Sergio Coronado's avatar
Sergio Coronado committed
219
* Others, like vim, emacs, Atom, Sublime, etc…
Sergio Coronado's avatar
Sergio Coronado committed
220
221
222

## File System explore
***
Christophe Trefois's avatar
Christophe Trefois committed
223
### Midnight Commander `mc`
Sarah Diehl's avatar
Sarah Diehl committed
224
225
226
* [Tutorial](http://linuxcommand.org/lc3_adv_mc.php)
* if function keys do not work, use `Esc`+`1` for `F1`, `Esc`+`2` for `F2`, ..., `Esc`+`9` for `F9` and `Esc`+`0` for `F10`
* if you do not have an `Insert` key (e.g. on Apple keyboards) use `Ctrl`+`t` for (un-)selecting files and folders
Sergio Coronado's avatar
Sergio Coronado committed
227
228
229

## Scripts – bash
***
230
* Simple `bash` scripting [Tutotial](http://linuxconfig.org/bash-scripting-tutorial)
Sergio Coronado's avatar
Sergio Coronado committed
231
232
233

## Basic git (source control)
***
Sergio Coronado's avatar
Sergio Coronado committed
234
235
236
* add
* commit
* push
Christophe Trefois's avatar
Christophe Trefois committed
237
* pull