From 65a45aacd31ddb1e75891d4ab396bbb72a44158e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Haugsb=C3=B8?= Date: Wed, 20 Nov 2024 09:38:43 +0100 Subject: [PATCH 01/11] Kubernetes better install commands --- content/docs/instrukser/kubernetes.md | 38 +++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/content/docs/instrukser/kubernetes.md b/content/docs/instrukser/kubernetes.md index 47a05ef..4d5ba20 100644 --- a/content/docs/instrukser/kubernetes.md +++ b/content/docs/instrukser/kubernetes.md @@ -16,7 +16,8 @@ Målet er å gjøre tjenestene enda mer robuste og enklere å vedlikeholde. Vi relevant for arbeidsliv. - https://docs.k3s.io/datastore/ha-embedded -- [ ] En/to HaProxy node som lastbalanserer mellom server nodene +- [x] En/to HaProxy node som lastbalanserer mellom server nodene (lb-1 & lb-2 på + letti & netti proxmox clusteret) - [x] Tre server noder (Kontrollerer klustert) - Petter.fribyte.no - Raptus.fribyte.no @@ -25,47 +26,56 @@ relevant for arbeidsliv. - lille-hjelper-1.fribyte.no - lille-hjelper-1.fribyte.no - lille-hjelper-1.fribyte.no +- [ ] Letsencrypt inni Kubernetes for å utstede sertifikater til tjenestene +- [ ] Simple static docker container eksempel ## Oppsett av kluster -[Installere k3sup](https://github.com/alexellis/k3sup?tab=readme-ov-file#download-k3sup-tldr) på Pluto, som har tilgang til NAT nettverket. +[Installere k3sup](https://github.com/alexellis/k3sup?tab=readme-ov-file#download-k3sup-tldr) +på Pluto, som har tilgang til NAT nettverket. Installer master og agent nodene med k3sup på Pluto: [Basert på denne kommandoen](https://github.com/alexellis/k3sup?tab=readme-ov-file#create-a-multi-master-ha-setup-with-embedded-etcd) - ```bash export USER=fribyte export K3S_VERSION="v1.31.2+k3s1" +# Tailscale IP of the ha proxy load balancer, needed to access kubectl over tailscale +export HA_PROXY_TAILSCALE_IP=100.64.0.43 + +# Server nodes export RAPTUS_IP=10.0.0.70 export PETTER_IP=10.0.0.71 export HUTRE_IP=10.0.0.72 +# Worker/agwnt nodes export LILLE_HJELPER_1_IP=10.0.0.80 export LILLE_HJELPER_2_IP=10.0.0.81 export LILLE_HJELPER_3_IP=10.0.0.82 # Master noder - -# Raptus -k3sup install --ip $RAPTUS_IP --user $USER --cluster --k3s-version $K3S_VERSION -# Petter -k3sup join --ip $PETTER_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --server --k3s-version $K3S_VERSION -# Hutre -k3sup join --ip $HUTRE_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --server --k3s-version $K3S_VERSION +k3sup install --ip $RAPTUS_IP --user $USER --cluster --k3s-version $K3S_VERSION --k3s-extra-args "--tls-san $HA_PROXY_TAILSCALE_IP" +k3sup join --ip $PETTER_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --server --k3s-version $K3S_VERSION --k3s-extra-args "--tls-san $HA_PROXY_TAILSCALE_IP" +k3sup join --ip $HUTRE_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --server --k3s-version $K3S_VERSION --k3s-extra-args "--tls-san $HA_PROXY_TAILSCALE_IP" # Agent noder - -# Lille-Hjelper-1 k3sup join --ip $LILLE_HJELPER_1_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --k3s-version $K3S_VERSION -# Lille-Hjelper-2 k3sup join --ip $LILLE_HJELPER_2_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --k3s-version $K3S_VERSION -# Lille-Hjelper-3 k3sup join --ip $LILLE_HJELPER_3_IP --user $USER --server-user $USER --server-ip $RAPTUS_IP --k3s-version $K3S_VERSION + +mv ./.kube/config ./.kube/config-$(date +%s) # Backup existing kubeconfig +mv kubeconfig ./.kube/config # WARNING - This will overwrite your existing kubeconfig kubectl label node lille-hjelper-1 kubernetes.io/role=agent kubectl label node lille-hjelper-2 kubernetes.io/role=agent kubectl label node lille-hjelper-3 kubernetes.io/role=agent ``` + +You can now access the Kubernetes cluster from your local machine by copying the +`~/.kube/config` file from Pluto to your local machine to the home directory. + +- And replace `server: https://10.0.0.70:6443` with + `server: https://100.64.0.43:6443` +- Confirm it is working using `kubectl get nodes` From 404f568974cdff4ff38218f8edc5ceea9ddbf505 Mon Sep 17 00:00:00 2001 From: P-15 Date: Tue, 10 Dec 2024 11:45:13 +0100 Subject: [PATCH 02/11] Add introduction to terminal page --- .../intro_terminal_v3_en.md | 523 ++++++++++++++++++ 1 file changed, 523 insertions(+) create mode 100644 content/docs/educational_resources/intro_terminal_v3_en.md diff --git a/content/docs/educational_resources/intro_terminal_v3_en.md b/content/docs/educational_resources/intro_terminal_v3_en.md new file mode 100644 index 0000000..435de6e --- /dev/null +++ b/content/docs/educational_resources/intro_terminal_v3_en.md @@ -0,0 +1,523 @@ +# Terminal introduction +## Intro +- To open a terminal in most Linux distributions you can use `Ctrl+Atl+T` (if + it doesn't work, you can try with `Atl+Enter`, `Alt+T`, `Ctrl+T` or something + like that or just look for it in the app launcher) +- What is between `<>` has to be substituted and the "<>" are removed. + - Ex: `cd ` ---> `cd Documents` +- Some commands can be given arguments that modify their behaviour. These can + also be called parameters, flags, options... +- Arguments are usually one letter long (but can be whole words) and are + written with a dash in front. +- If you want to give a command more than one argument, you can put them + together. + - E.g.: `ls -a -l -h` ---> `ls -alh` (as a general rule, the order of the + parameters is not important `-alh` = `-hla`) +- Commands, arguments, file/directory names... are all case sensitive. + - E.g.: "Documents" is not the same directory as "documents" +- When a command doesn't work **read the error message**. Most of the time it + will tell you exactly what went wrong and how to fix it. +- If the terminal completely freezes at some point it's possible that you + pressed Ctrl+S by mistake. To unfreeze simply press Ctrl+Q. + +## File hierarchy +In Linux the file system has a tree structure and all files and directories are +under the root directory, represented as `/` (the root of the tree). For example, +the user's home directory is in the path `/home`, which means inside the +directory "home" which is inside the directory "/" (root). + +There are two types of paths, absolute and relative. +- Absolute paths always start at root and indicate how to reach a file or + directory from there. They work independently of where you are in the file + system at the moment. When a path starts with `/` it's **always** absolute and the + system will start at the root of the file tree. +- Relative paths depend on the directory in which you are located in that + moment, so they can't be used from any place. The system follows the + "directions" of the path starting at the directory you are currently on. + +Example: +- `/home/my_usr/Desktop/dir1/file.txt` +- `dir1/file.txt` + +Both paths go to the same file, but for the second example you have to be +located in the Desktop directory for it to work and it doesn't begin with `/` +because its relative, and only absolute paths (like the first one) begin with +`/`. It's advisable to use absolute paths for scripts so that they can be +executed from any directory without giving error. + +There's a series of "special directories" that can be used in paths: +- `..` : it indicates the previous/parent directory. If you move to `..` from + `Desktop/dir`, you will end up in `Desktop`. +- `.` : it indicates your current directory. It's useful when you want to copy a + file to where you are (copy file to `.`) +- `~` : it indicates your home directory (`/home/my_usr`). It's the directory in + which you start when you open a terminal. The paths that use it are a bit + different from relative and absolute paths until now. It is relative to the + user (if you are logged in into another account it won't work) but inside the + user directory, it could be said to be absolute, as it doesn't matter in + which directory you are (`~/Desktop/dir1` works even if you are inside + `/home/my_usr/Documents/dir2`) + +For more information about the structure of the Linux file system you can read +https://linuxhandbook.com/linux-directory-structure/ + +## ls [LiSt] +Lists the files (and subdirectories) in a directory (same as looking at them +in the graphical file manager). + +The contents of a directory are printed in different colours, which normally +are: +- **White:** files +- **Bold blue:** directories (folders) +- **Bold green:** executable files (if it's not green it doesn't necessarily mean + that file is not meant to be executed, it just means you don't have the + permissions to do it) +(If it's not coloured by default you can try to use the parameter `--color=auto`) + +You can use paths to make it list the contents of a specific directory (`ls ..` | +`ls Desktop/dir`). By default it uses your current directory (so it's the same as +specifying `ls .`) + +In Linux, files and directories with a name starting by `.` are considered +hidden. This means they won't be shown by default when you execute `ls` (or in +the graphical file manager). It's used, for example, for configuration files, +to avoid having them clutter the home directory and make it easier to navigate +the files that are actually interesting for the user. + +- `ls -a`: shows [a]ll, including hidden files. +- `ls -l`: [l]ists information about the files (like size, last modified date, + permissions...) +- `ls -lh`: shows the file size in [h]uman readable mode (transforms to KB, + GB... instead of writing it in bytes). + +## cd [Change Directory] +Allows to move between directories using absolute or relative paths (equivalent +to clicking on a folder in the graphical file manager). + +- `cd ` +- You can concatenate more than one directory : `cd dir1/dir2/dir3` (where `dir2` + is a subdirectory of `dir1` and `dir3` of `dir2`) +- To go to the previous/parent directory : `cd ..` +- `cd` on its own takes you to your home directory (same as `cd ~`) +- `cd -` : goes to the directory in which you previously were. + - e.g.: if you're in `~/Desktop/dir1` and make `cd ~/Documents/dir2`, executing + `cd -` will take you back to dir1. If you execute it again, it will take + you to `dir2`, and you can toggle between those two until you move to a + third directory. + - e.g.: if you were in `~/this/is/a/directory/with/a/very/long/path` and you + accidentally execute `cd` and go back to `~` (home), then instead of writing + everything again you can just do `cd -` + +## mkdir [MaKe DIRectory] +Creates a directory. + +- `mkdir `: creates "directory" as a subdirectory in your current path + +- You can write the path in which you want the directory to be created, but all + previous directories have to exist. + - E.g.: If you create a directory inside Documents (being the absolute path + `/home/my_usr/Documents`), it only works if `home`, `my_usr` and `Documents` + currently exist. You can use relative or absolute paths: + - `mkdir /home/my_usr/Documents/new_dir` + - `mkdir Documents/new_dir` + +- You can create more than one directory at once: + - `mkdir dir1 dir2`: `dir1` and `dir2` are created in your current directory + - `mkdir Documents/dir1 Desktop/dir2`: `dir1` is created inside `Documents` and + `dir2` is created inside `Desktop` +- If you want to create `dir2` in `Desktop/dir1/dir2` but `dir1` doesn't exist, you + can use the `-p` parameter to tell it to automatically create every directory + needed: + - `mkdir -p Desktop/dir1/dir2`: creates `dir1` and then creates `dir2` inside + +## cat +Prints the contents of a text file to the terminal. +- `cat ` +- `cat -n `: prints the file with numbered lines + +

+ +--- + +**WARNING: THE NEXT THREE COMMANDS ARE USED TO MOVE, RENAME, COPY AND ERASE +FILES. IT'S IMPORTANT TO TAKE INTO ACCOUNT THAT THE TERMINAL DOESN'T HAVE AN +UNDO BUTTON AND THERE IS NO BIN FOLDER WHERE DELETED FILES ARE SENT. IF +SOMETHING GETS ERASED, OVERWRITTEN OR LOST, THERE IS NO WAY OF GETTING IT BACK. +IT'S NOT A MATTER OF NEVER USING THESE COMMANDS, BUT IT'S IMPORTANT TO KNOW +WHAT YOU ARE DOING, SPECIALLY IF YOU ARE USING WILDCARDS (EXPLAINED LATER).** + +--- + +## mv [MoVe] +Moves/renames files and directories. + +#### Moving +You specify the file (or files) you want to move and the destination (which has +to be common for all files). +- `mv ` +- `mv test.txt ib`: moves the file `test.txt` to the directory `ib` +- `mv dir ib`: moves the directory `dir` to the directory `ib` +- `mv test.txt dir ib`: moves file `test.txt` and directory `dir` to `ib` + +You can use the path modifiers: +- `mv file ..`: moves the file to the parent directory + +**Warning: If the destination doesn't exists and there is only one file/directory +to move, it will rename it (to the destination name). If there is more than one +file/directory to move, it will just give an error.** + +#### Renaming +You specify the file you want to rename and the new name. +- `mv ` +- `mv fle.txt file.txt`: renames file `fle.txt` to `file.txt` +- `mv dir dir1`: renames directory `dir` to `dir1` +- `mv dir/file dir/file1`: renames file to `file1` inside the `dir` directory + +**Warning: if the file already exists, it will be overwritten. If it exists but +it's a directory, it will instead move it to the directory.** + +#### Combining both +You can combine the move and rename operations: +- `mv dir/file file1`: moves file to the current directory (`./file1`) and renames + it to `file1` +- `mv file dir/file1`: moves `file` to the directory `dir` and renames it as `file1` +- `mv dir/dir1 dir2`: moves `dir1` to the current directory and renames it as `dir2` +- `mv dir1 dir/dir2`: moves `dir1` to the directory `dir` and renames it as `dir2` + +If a file hasn't been moved to where you expected and you can't find it +anymore, try taking a careful look at the command and see if you could have +renamed the file by accident. + +## cp [CoPy] +Copies files/directories (can automatically rename the copy) + +- `cp ` + - `cp test.txt ib`: copies `test.txt` to the `ib` directory + - `cp test.txt ib/test_copy.txt`: copies `test.txt` to the `ib` directory and + renames it as `test_copy.txt` +- If you want to copy a directory you need to use the `-r` (recursive) flag so + that it recursively copies the contents of the directory as well (if you + forget, it simply gives an error and reminds you to do it). + +For this command as well you can use the special path specifiers. +- `cp dir/test.txt .`: copies `test.txt` from the `dir` to the current directory +- `cp file ..`: copies the file to the parent directory + +## rm [ReMove] +Deletes files/directories. + +There shouldn't be any problem with using it if you are careful with what you +do (aka, don't just paste the first command you find on the Internet without +knowing what it does) but, if you feel more comfortable, you can always create +a command that moves the files to a Bin directory instead, and then you can use +rm inside it (see aliases in [Other interesting concepts to learn about](##Other interesting concepts to learn about)). + +- `rm `: removes the file +- `rmdir `: removes a directory but **only** if it's empty (useful if you + want to make sure all directories you are erasing have nothing left inside). +- `rm -r `: removes recursively (the directory and its contents). + Just like with `cp`, if you forget to put the `-r` the terminal will give an + error (directory isn't empty). If it is empty, it will tell you to use `rmdir` + but you can also use `rm -r`. + +## nano +Simple terminal text editor. Because it works on the terminal, mouse support +isn't activated by default (but there is an option to use it though). This +means you need to use the arrow keys to move the cursor. + +- `nano `: opens a file to edit it. If it doesn't exists it creates it. +- **Ctrl+O**: saves the changes (capital O, not zero) and asks you what name you + want to use. If you don't want to save them to a new file, just hit enter. +- **Ctrl+X**: exists the editor (if you haven't saved it will prompt you to do + it). +There's a cheat sheet in the base of the editor with other useful keybindings. + +## VS Code +If you use VS Code as you editor, you can launch it form the terminal (which is +useful when you are already in the directory you want to work on). +- `code`: opens VS Code +- `code `: opens the file in VS Code +- `code `: opens the directory in VS Code (if you are currently in it you + can use `code .`) + +## file +In Linux, file extensions are only useful as a reference for the user, the +system ignores them and they don't have to really correspond to the real type +of the file or be there at all (they can be omitted). To check the type of a +file you can use the file command. + +- `file `: indicates the type of the file + +## sudo +In Linux there exists a special user called root. This superuser has the +permissions to do almost anything in the computer and it would be the +equivalent of an administrator role. A user can have the permissions to execute +commands as root and there are two ways of doing it. The first one is to log in +as the superuser, which is dangerous because the computer will execute whatever +you ask for without thinking twice about it. The second option (recommended) is +writing `sudo` in front of the command you need to execute as root. The rest of +your commands will be executed with normal permissions. + +- `apt install` ---> `sudo apt install` +- `rm file` ---> `sudo rm file` + +## sudoedit +When you are going to edit a system file, instead of using `sudo` directory it's +recommendable to use `sudoedit`. + +- `sudo ` ----> `sudoedit ` + +The command opens the file using your default editor (you can change it by +adding the line `export VISUAL=` at the end of your `.bashrc` file in +your home) + +The first reason to use `sudoedit` is that it's safer. The command makes a copy +of the system file which the user can edit and, when you are finished making +changes to it, it writes them to the original file. Using `sudo`, the file is +opened by the superuser, who has permissions to execute whatever command or +delete that file or any other (in nano you can't, but if you use other editors +like vim, you can open terminals or execute commands from inside it and those +would be executed with root permissions). With `sudoedit`, everything will be +done as your user, so there are less probabilities that something goes terribly +wrong. + +The second and more practical reason is, as it's executed as your user and not +as root, the command uses your editor configuration. Again, maybe if you use +nano it doesn't make much of a difference, but if you have a more configurable +or extensible editor you can use your configuration when editing the system +files instead of having to stick with the root config (which will probably be +the default one). + +## Other commands +- `clear`: clears the terminal (erases everything written and brings the cursor + back to the top) +- `exit`: exists the terminal +- `find -name `: finds every file/directory inside `dir` that has the + name `name`. It has to be the exact name (unless you use wildcards) +- `history`: shows the history of commands +- `pwd` [Print Working Directory]: prints to the terminal the absolute path to + the directory you are currently in +- `less `: same as `cat`, it prints the contents of a text file, but less + allows you to scroll through them +- zoxide: alternative to `cd` that stores a list with your most visited + directories and jumps directly to the first one that matches the string you + give it (not installed by default) + - `z Doc`: could jump to `~/Documents` + - `z screen `: could jump to `~/Desktop/pictures/screenshots` + - `z shots `: could also jump to `~/Desktop/pictures/screenshots` +- `grep`: allows to search inside of files or in the output of a command (for + example, if ls has a big output and you want to see if there is some pdf, you + can use `grep` to search the ".pdf" string inside the output of `ls`). It's + recommended to learn about redirections beforehand, since they will be + specially useful here (in [Other interesting concepts to learn about](##Other interesting concepts to learn about)) + - `grep `: prints all lines `file` that contain `string` + - `grep -i `: the search is case insensitive +- `xkill`: if a window freezes and stops responding, you can execute `xkill` inside + a terminal and click with the mouse on the offending window to kill it. + +## Other concepts +- To copy and paste, highlight the text to copy and press the mouse wheel to + paste it. You can also use Ctrl+Shift+C and Ctrl+Shift+V. +- To interrupt a command : Ctrl+C +- Up arrow to see previous commands (goes through the command history). It + allows you to execute them again or edit them. +- Tab autocompletes commands and file names. If there is more than one option, + pressing it twice shows all possibilities (pressing it once seems to do + nothing, that's when you know there are various options or none at all). Its + use is recommended, not only to type quicker but to make sure the + command/file exists and is correctly written (take into account that there + isn't autocompletion of parameters for all commands). + - `cd Do` [tab tab] + > Documents/ \ + Downloads/ \ + Doc.txt +- Many commands have the option `-v` to make the output more [v]erbose + (outputs more information about what the command is doing) +- Instead of using the command `clear`, it's possible to clean the screen using + Ctrl+L. This has the added advantage that if you already have a command + written you don't need to erase it in order to clear the screen. +- Instead of using `exit` you can exit the terminal by pressing Ctrl+D. For + this you *do* need to have no input in the command line. + +## The wildcard +In Linux, `*` represents the wildcard. It tells the terminal that it can +substitute the asterisk by anything, including nothing. If you tell it to move +to a directory every file with the name `*ing`, it will move the files "ing", +"programming", "editing"... because they all end in "ing", whatever goes before +doesn't matter (you have indicated it can be anything). However, the file +"programming.txt" will not be moved. To include it you would have to indicate +that it should also not care about what comes after "ing" (`*ing*`). + +Another example would be if you have the files "ing.pdf", "ing.txt", +"programming.txt" and "editing" and you just want to move the first two. For +this you would use `ing*`, indicating that the file has to start with "ing" and +whatever goes after doesn't matter. + +This is very useful when you want to move al pdf files to a directory, for example: +- `mv *.pdf pdf-dir/` : moves every file that ends in ".pdf" +(We have to remember that in Linux you don't need to have the appropriate +extension in every file, so this would move all files with a name ending in +pdf, not necessarily all pdf files. But if the conventions are followed, which +normally are, it should be the same in the end) + +Correspondingly, if you have a bunch of files starting in the same way and want +to erase them all, you can write the start string and add `*`. +- `rm erasable*`: will erase "erasable_edited.pdf", "erasable_original.pdf", + "erasable.txt"... + +**BE VERY CAREFUL WHEN USING WILDCARDS, SPECIALLY WITH RM.** If written on its own +(`rm *`) it will erase everything in the directory (you are telling the system to +erase everything with any name). This can be very useful but also very +dangerous. + +## Help +- `apropos `: searches for `string` in the list of installed commands + (has the command name and a brief description). + - E.g.: `apropos editor` + > ... \ + nano (1) - Nano's ANOther text editor, inspired by Pico \ + ... +- `man `: prints the command's [man]ual. Most commands (specially the + most used ones) have a manual page. However, sometimes it can be difficult to + understand, specially when you are starting. You press `Q` to exit the + command page and yes, there is a manual for the manual (`man man`). +- `--help`: many commands accept this parameter and print a shorter version of + the manual. +- `tldr` [Too Long Didn't Read] : instead of an extensive file about what the + command does and every single possible option it has, `tldr` just gives a + couple of examples of its most typical uses. The tldr pages are downloaded as + you access them, so it's possible you need access to the Internet and they + can take a bit to load if you haven't used it before. To avoid this you can + do `tldr --update`(tldr is not installed by default). +- `cheat`: allows the use of cheat sheets. You can install the ones premade by + the community (which is useful) but the most interesting thing about cheat is + that it allows you to create your own entries. This way you can write your + own cheat sheets as you go on learning new commands and parameters, to have + everything handy and not have to look it up from scratch again (this command + is not installed by default) + - `cheat `: prints the cheat sheet for `command` + - `cheat -e `: edits the cheat sheet for `command`. If it doesn't + exist it is created. + +My recommendation is: when you need to find a new command use `apropos` or the +Internet ("terminal how to edit text file", "terminal merge pdfs"). When you +know the command but need the parameters, use `tldr` or `cheat`. These tell you +what to write to get the desired result, but they don't explain you the +command. You can use `man` to search for the explanation for those parameters +(you search by pressing `/` [ex: `/-l` + Enter] and move between the results with `n` +and `N`). This way, you start to get comfortable with the manual without having +to depend completely on it. If all fails, the Internet is your friend. I'd +write down everything you learn on a text file, for future reference, or if +it's a specific example for a command inside a cheat cheat sheet. Sometimes it +takes a while to get the exact command you need and this saves you time the +next time you have to use it. + +## Useless comands everyone should know +They aren't installed by default and usually have a bunch of parameters and +options you can learn about in the help pages (`man`, `tldr`...). +- `cowsay `: prints a cow with a speech bubble that has `text` inside. With + the parameter `-f` you can change the ascii drawing (my favourite is the + stegosaurus with a hat) +- `sl`: animation of a train crossing your terminal. You can't stop it with + Ctrl+C (they used "sl" to nag everyone that mistypes `ls` so not being able to + stop it is on purpose). It has a couple of options, like people screaming for + help or making the train fly. +- `cmatrix`: characters falling through your terminal screen +- `espeak`: text-to-speech +- `fortune`: prints a random fortune (like the ones from the cookies). You can + create your on fortune files and use them instead of or with the default ones + (it is also useful when you want a quick way of getting a random sentence + from a set of them) +- `oneko`: renders a cat that follows your cursor through the screen. +- `xeyes`: a classic. Eyes that follow your cursor (if you use Wayland they won't + work correctly) +- `toilet`/`figlet`: print asciiart text +- `rig`: creates a random identity (name-surname and address) +- `xpenguins` and `xsnow`: might not work everywhere (even inside X11) but should + make a bunch of penguins appear and start moving through your screen (for the + first one) and snow fall from the top of your screen and on top of your + windows (for the second one). +- `lolcat`: prints multicoloured text. It's usually used with command redirection + (e.g.: `ls | lolcat`). +- `neofetch`/`fastfetch` (and others): print an ascii drawing of your distro's logo + (this can be changed) and your device specs (distro, desktop environment, + RAM, CPU...). Neofetch is he most typical one but it has been discontinued + and fastfetch is faster. Both can be personalized but neofetch has many + pre-designed themes. + - NeoCat (neofetch themes): https://github.com/m3tozz/NeoCat + - Neofetch-themes: https://github.com/Chick2D/neofetch-themes/tree/main + + +## Other interesting concepts to learn about +- Package manager: the most practical way of installing packages in Linux. + Depending on the distro you will use one manager or another but the important + thing is to learn the commands to update/upgrade the system and install, + remove and search packages. +- Redirection: allows the concatenation of commands, redirecting the output of + one to the input of the next one or to a file. + https://www.freecodecamp.org/news/linux-terminal-piping-and-redirection-guide/ +- Alias: you can create an alias for a command to give it a different name (so + you can write `potato` instead of `sudo`) or to simplify certain combinations of + parameters that you use a lot (`ll` instead of `ls -lh`). + https://www.freecodecamp.org/news/how-to-add-aliases-to-terminal-commands/ + (in most distros you don't need to touch the `.bashrc`. If you create a + `.bash_aliases` file in your home directory it detects it automatically. This + allows you to have an alias-specific file, cleaner and more concise). +- Automation: terminal scripts allow to automate many things and cron is also + very useful for this, allowing to execute commands at certain hours/days + automatically. + - Bash Scripting Tutorial: + https://ryanstutorials.net/bash-scripting-tutorial/ + - Understanding Crontab in Linux with Examples: + https://linuxhandbook.com/crontab/ +- zsh: bash is the default shell for many distros but there are others. One of + the better known is zsh, due to its ample functionality and configurability, + like syntax highlighting in the command line. It's usually installed + alongside ohmyzsh, which allows to easily configure it and install + extensions. + - ohmyzsh web page: https://ohmyz.sh/ + - ohmyzsh GitHub: https://github.com/ohmyzsh/ohmyzsh +- `hollywood`: just some Hollywood-hacking magic (just keep pressing Ctrl+C to + exit it) + +## Other resources +Some useful resources to learn how to use the terminal and Linux in general. +I haven't looked at them all and they aren't in any particular order. + +#### Tools/documentation: +- Explain Shell: you write a command and it explains what each part does (not + perfect but it can help) https://explainshell.com/ + +#### Courses +- Linux Journey: web page to learn the Linux basics https://linuxjourney.com/ +- Beginner's Guide to the Bash Terminal (video): + https://www.youtube.com/watch?v=oxuRxtrO2Ag +- The Linux Command Line (book): https://www.linuxcommand.org/ +- Linux Terminal - Getting Started! (video series): + https://www.youtube.com/watch?v=b5NmtmNwMgU&list=PLW5y1tjAOzI2ZYTlMdGzCV8AJuoqW5lKB +- Text adventure game using the terminal commands (video game): + https://web.mit.edu/mprat/Public/web/Terminus/Web/main.html +- Learning Terminal in Linux (video series): + https://www.youtube.com/playlist?list=PLc7fktTRMBozYfi4zlDeH0IdLdGImeOnO +- Linux Tutorial: https://ryanstutorials.net/linuxtutorial/ +- The Unix Shell: https://swcarpentry.github.io/shell-novice/ + +#### Articles +- Command Line for Beginners - How to Use the Terminal Like a Pro: + https://www.freecodecamp.org/news/command-line-for-beginners/ +- How to Type Less and Work Faster in the Linux Terminal: + https://www.howtogeek.com/815219/how-to-work-faster-in-linux-terminal/ + +#### Interesting blogs +- ItsFOSS: News and tutorials about the free software world in general: + https://itsfoss.com/ +- Linux Handbook: Linux courses and tutorials: https://linuxhandbook.com/ +- FreeCodeCamp: articles and courses about computers science in general: + https://www.freecodecamp.org/ +- LinuxOPsys: linux tutorials and tips: https://linuxopsys.com/ + +#### YouTube channels +- Learn Linux TV: https://www.youtube.com/@LearnLinuxTV/videos +- Veronica Explains: https://www.youtube.com/@VeronicaExplains/videos +- The Linux Experiment (Linux news): https://www.youtube.com/@TheLinuxEXP/videos + From 9efe620cffe0c88574025c6b4876ea68591402e3 Mon Sep 17 00:00:00 2001 From: P-15 Date: Tue, 10 Dec 2024 12:03:34 +0100 Subject: [PATCH 03/11] Remove unnecessary new lines --- .../intro_terminal_v3_en.md | 430 +++++------------- 1 file changed, 115 insertions(+), 315 deletions(-) diff --git a/content/docs/educational_resources/intro_terminal_v3_en.md b/content/docs/educational_resources/intro_terminal_v3_en.md index 435de6e..7f94ab9 100644 --- a/content/docs/educational_resources/intro_terminal_v3_en.md +++ b/content/docs/educational_resources/intro_terminal_v3_en.md @@ -1,133 +1,80 @@ # Terminal introduction ## Intro -- To open a terminal in most Linux distributions you can use `Ctrl+Atl+T` (if - it doesn't work, you can try with `Atl+Enter`, `Alt+T`, `Ctrl+T` or something - like that or just look for it in the app launcher) +- To open a terminal in most Linux distributions you can use `Ctrl+Atl+T` (if it doesn't work, you can try with `Atl+Enter`, `Alt+T`, `Ctrl+T` or something like that or just look for it in the app launcher) - What is between `<>` has to be substituted and the "<>" are removed. - Ex: `cd ` ---> `cd Documents` -- Some commands can be given arguments that modify their behaviour. These can - also be called parameters, flags, options... -- Arguments are usually one letter long (but can be whole words) and are - written with a dash in front. -- If you want to give a command more than one argument, you can put them - together. - - E.g.: `ls -a -l -h` ---> `ls -alh` (as a general rule, the order of the - parameters is not important `-alh` = `-hla`) +- Some commands can be given arguments that modify their behaviour. These can also be called parameters, flags, options... +- Arguments are usually one letter long (but can be whole words) and are written with a dash in front. +- If you want to give a command more than one argument, you can put them together. + - E.g.: `ls -a -l -h` ---> `ls -alh` (as a general rule, the order of the parameters is not important `-alh` = `-hla`) - Commands, arguments, file/directory names... are all case sensitive. - E.g.: "Documents" is not the same directory as "documents" -- When a command doesn't work **read the error message**. Most of the time it - will tell you exactly what went wrong and how to fix it. -- If the terminal completely freezes at some point it's possible that you - pressed Ctrl+S by mistake. To unfreeze simply press Ctrl+Q. +- When a command doesn't work **read the error message**. Most of the time it will tell you exactly what went wrong and how to fix it. +- If the terminal completely freezes at some point it's possible that you pressed Ctrl+S by mistake. To unfreeze simply press Ctrl+Q. ## File hierarchy -In Linux the file system has a tree structure and all files and directories are -under the root directory, represented as `/` (the root of the tree). For example, -the user's home directory is in the path `/home`, which means inside the -directory "home" which is inside the directory "/" (root). +In Linux the file system has a tree structure and all files and directories are under the root directory, represented as `/` (the root of the tree). For example, the user's home directory is in the path `/home`, which means inside the directory "home" which is inside the directory "/" (root). There are two types of paths, absolute and relative. -- Absolute paths always start at root and indicate how to reach a file or - directory from there. They work independently of where you are in the file - system at the moment. When a path starts with `/` it's **always** absolute and the - system will start at the root of the file tree. -- Relative paths depend on the directory in which you are located in that - moment, so they can't be used from any place. The system follows the - "directions" of the path starting at the directory you are currently on. +- Absolute paths always start at root and indicate how to reach a file or directory from there. They work independently of where you are in the file system at the moment. When a path starts with `/` it's **always** absolute and the system will start at the root of the file tree. +- Relative paths depend on the directory in which you are located in that moment, so they can't be used from any place. The system follows the "directions" of the path starting at the directory you are currently on. Example: - `/home/my_usr/Desktop/dir1/file.txt` - `dir1/file.txt` -Both paths go to the same file, but for the second example you have to be -located in the Desktop directory for it to work and it doesn't begin with `/` -because its relative, and only absolute paths (like the first one) begin with -`/`. It's advisable to use absolute paths for scripts so that they can be -executed from any directory without giving error. +Both paths go to the same file, but for the second example you have to be located in the Desktop directory for it to work and it doesn't begin with `/` because its relative, and only absolute paths (like the first one) begin with `/`. It's advisable to use absolute paths for scripts so that they can be executed from any directory without giving error. There's a series of "special directories" that can be used in paths: -- `..` : it indicates the previous/parent directory. If you move to `..` from - `Desktop/dir`, you will end up in `Desktop`. -- `.` : it indicates your current directory. It's useful when you want to copy a - file to where you are (copy file to `.`) -- `~` : it indicates your home directory (`/home/my_usr`). It's the directory in - which you start when you open a terminal. The paths that use it are a bit - different from relative and absolute paths until now. It is relative to the - user (if you are logged in into another account it won't work) but inside the - user directory, it could be said to be absolute, as it doesn't matter in - which directory you are (`~/Desktop/dir1` works even if you are inside - `/home/my_usr/Documents/dir2`) +- `..` : it indicates the previous/parent directory. If you move to `..` from `Desktop/dir`, you will end up in `Desktop`. +- `.` : it indicates your current directory. It's useful when you want to copy a file to where you are (copy file to `.`) +- `~` : it indicates your home directory (`/home/my_usr`). It's the directory in which you start when you open a terminal. The paths that use it are a bit different from relative and absolute paths until now. It is relative to the user (if you are logged in into another account it won't work) but inside the user directory, it could be said to be absolute, as it doesn't matter in which directory you are (`~/Desktop/dir1` works even if you are inside `/home/my_usr/Documents/dir2`) For more information about the structure of the Linux file system you can read https://linuxhandbook.com/linux-directory-structure/ ## ls [LiSt] -Lists the files (and subdirectories) in a directory (same as looking at them -in the graphical file manager). +Lists the files (and subdirectories) in a directory (same as looking at them in the graphical file manager). -The contents of a directory are printed in different colours, which normally -are: +The contents of a directory are printed in different colours, which normally are: - **White:** files - **Bold blue:** directories (folders) -- **Bold green:** executable files (if it's not green it doesn't necessarily mean - that file is not meant to be executed, it just means you don't have the - permissions to do it) +- **Bold green:** executable files (if it's not green it doesn't necessarily mean that file is not meant to be executed, it just means you don't have the permissions to do it) (If it's not coloured by default you can try to use the parameter `--color=auto`) -You can use paths to make it list the contents of a specific directory (`ls ..` | -`ls Desktop/dir`). By default it uses your current directory (so it's the same as -specifying `ls .`) +You can use paths to make it list the contents of a specific directory (`ls ..` | `ls Desktop/dir`). By default it uses your current directory (so it's the same as specifying `ls .`) -In Linux, files and directories with a name starting by `.` are considered -hidden. This means they won't be shown by default when you execute `ls` (or in -the graphical file manager). It's used, for example, for configuration files, -to avoid having them clutter the home directory and make it easier to navigate -the files that are actually interesting for the user. +In Linux, files and directories with a name starting by `.` are considered hidden. This means they won't be shown by default when you execute `ls` (or in the graphical file manager). It's used, for example, for configuration files, to avoid having them clutter the home directory and make it easier to navigate the files that are actually interesting for the user. - `ls -a`: shows [a]ll, including hidden files. -- `ls -l`: [l]ists information about the files (like size, last modified date, - permissions...) -- `ls -lh`: shows the file size in [h]uman readable mode (transforms to KB, - GB... instead of writing it in bytes). +- `ls -l`: [l]ists information about the files (like size, last modified date, permissions...) +- `ls -lh`: shows the file size in [h]uman readable mode (transforms to KB, GB... instead of writing it in bytes). ## cd [Change Directory] -Allows to move between directories using absolute or relative paths (equivalent -to clicking on a folder in the graphical file manager). +Allows to move between directories using absolute or relative paths (equivalent to clicking on a folder in the graphical file manager). - `cd ` -- You can concatenate more than one directory : `cd dir1/dir2/dir3` (where `dir2` - is a subdirectory of `dir1` and `dir3` of `dir2`) +- You can concatenate more than one directory : `cd dir1/dir2/dir3` (where `dir2` is a subdirectory of `dir1` and `dir3` of `dir2`) - To go to the previous/parent directory : `cd ..` - `cd` on its own takes you to your home directory (same as `cd ~`) - `cd -` : goes to the directory in which you previously were. - - e.g.: if you're in `~/Desktop/dir1` and make `cd ~/Documents/dir2`, executing - `cd -` will take you back to dir1. If you execute it again, it will take - you to `dir2`, and you can toggle between those two until you move to a - third directory. - - e.g.: if you were in `~/this/is/a/directory/with/a/very/long/path` and you - accidentally execute `cd` and go back to `~` (home), then instead of writing - everything again you can just do `cd -` + - e.g.: if you're in `~/Desktop/dir1` and make `cd ~/Documents/dir2`, executing `cd -` will take you back to dir1. If you execute it again, it will take you to `dir2`, and you can toggle between those two until you move to a third directory. + - e.g.: if you were in `~/this/is/a/directory/with/a/very/long/path` and you accidentally execute `cd` and go back to `~` (home), then instead of writing everything again you can just do `cd -` ## mkdir [MaKe DIRectory] Creates a directory. - `mkdir `: creates "directory" as a subdirectory in your current path -- You can write the path in which you want the directory to be created, but all - previous directories have to exist. - - E.g.: If you create a directory inside Documents (being the absolute path - `/home/my_usr/Documents`), it only works if `home`, `my_usr` and `Documents` - currently exist. You can use relative or absolute paths: +- You can write the path in which you want the directory to be created, but all previous directories have to exist. + - E.g.: If you create a directory inside Documents (being the absolute path `/home/my_usr/Documents`), it only works if `home`, `my_usr` and `Documents` currently exist. You can use relative or absolute paths: - `mkdir /home/my_usr/Documents/new_dir` - `mkdir Documents/new_dir` - You can create more than one directory at once: - `mkdir dir1 dir2`: `dir1` and `dir2` are created in your current directory - - `mkdir Documents/dir1 Desktop/dir2`: `dir1` is created inside `Documents` and - `dir2` is created inside `Desktop` -- If you want to create `dir2` in `Desktop/dir1/dir2` but `dir1` doesn't exist, you - can use the `-p` parameter to tell it to automatically create every directory - needed: + - `mkdir Documents/dir1 Desktop/dir2`: `dir1` is created inside `Documents` and `dir2` is created inside `Desktop` +- If you want to create `dir2` in `Desktop/dir1/dir2` but `dir1` doesn't exist, you can use the `-p` parameter to tell it to automatically create every directory needed: - `mkdir -p Desktop/dir1/dir2`: creates `dir1` and then creates `dir2` inside ## cat @@ -139,12 +86,7 @@ Prints the contents of a text file to the terminal. --- -**WARNING: THE NEXT THREE COMMANDS ARE USED TO MOVE, RENAME, COPY AND ERASE -FILES. IT'S IMPORTANT TO TAKE INTO ACCOUNT THAT THE TERMINAL DOESN'T HAVE AN -UNDO BUTTON AND THERE IS NO BIN FOLDER WHERE DELETED FILES ARE SENT. IF -SOMETHING GETS ERASED, OVERWRITTEN OR LOST, THERE IS NO WAY OF GETTING IT BACK. -IT'S NOT A MATTER OF NEVER USING THESE COMMANDS, BUT IT'S IMPORTANT TO KNOW -WHAT YOU ARE DOING, SPECIALLY IF YOU ARE USING WILDCARDS (EXPLAINED LATER).** +**WARNING: THE NEXT THREE COMMANDS ARE USED TO MOVE, RENAME, COPY AND ERASE FILES. IT'S IMPORTANT TO TAKE INTO ACCOUNT THAT THE TERMINAL DOESN'T HAVE AN UNDO BUTTON AND THERE IS NO BIN FOLDER WHERE DELETED FILES ARE SENT. IF SOMETHING GETS ERASED, OVERWRITTEN OR LOST, THERE IS NO WAY OF GETTING IT BACK. IT'S NOT A MATTER OF NEVER USING THESE COMMANDS, BUT IT'S IMPORTANT TO KNOW WHAT YOU ARE DOING, SPECIALLY IF YOU ARE USING WILDCARDS (EXPLAINED LATER).** --- @@ -152,8 +94,7 @@ WHAT YOU ARE DOING, SPECIALLY IF YOU ARE USING WILDCARDS (EXPLAINED LATER).** Moves/renames files and directories. #### Moving -You specify the file (or files) you want to move and the destination (which has -to be common for all files). +You specify the file (or files) you want to move and the destination (which has to be common for all files). - `mv ` - `mv test.txt ib`: moves the file `test.txt` to the directory `ib` - `mv dir ib`: moves the directory `dir` to the directory `ib` @@ -162,9 +103,7 @@ to be common for all files). You can use the path modifiers: - `mv file ..`: moves the file to the parent directory -**Warning: If the destination doesn't exists and there is only one file/directory -to move, it will rename it (to the destination name). If there is more than one -file/directory to move, it will just give an error.** +**Warning: If the destination doesn't exists and there is only one file/directory to move, it will rename it (to the destination name). If there is more than one file/directory to move, it will just give an error.** #### Renaming You specify the file you want to rename and the new name. @@ -173,31 +112,24 @@ You specify the file you want to rename and the new name. - `mv dir dir1`: renames directory `dir` to `dir1` - `mv dir/file dir/file1`: renames file to `file1` inside the `dir` directory -**Warning: if the file already exists, it will be overwritten. If it exists but -it's a directory, it will instead move it to the directory.** +**Warning: if the file already exists, it will be overwritten. If it exists but it's a directory, it will instead move it to the directory.** #### Combining both You can combine the move and rename operations: -- `mv dir/file file1`: moves file to the current directory (`./file1`) and renames - it to `file1` +- `mv dir/file file1`: moves file to the current directory (`./file1`) and renames it to `file1` - `mv file dir/file1`: moves `file` to the directory `dir` and renames it as `file1` - `mv dir/dir1 dir2`: moves `dir1` to the current directory and renames it as `dir2` - `mv dir1 dir/dir2`: moves `dir1` to the directory `dir` and renames it as `dir2` -If a file hasn't been moved to where you expected and you can't find it -anymore, try taking a careful look at the command and see if you could have -renamed the file by accident. +If a file hasn't been moved to where you expected and you can't find it anymore, try taking a careful look at the command and see if you could have renamed the file by accident. ## cp [CoPy] Copies files/directories (can automatically rename the copy) - `cp ` - `cp test.txt ib`: copies `test.txt` to the `ib` directory - - `cp test.txt ib/test_copy.txt`: copies `test.txt` to the `ib` directory and - renames it as `test_copy.txt` -- If you want to copy a directory you need to use the `-r` (recursive) flag so - that it recursively copies the contents of the directory as well (if you - forget, it simply gives an error and reminds you to do it). + - `cp test.txt ib/test_copy.txt`: copies `test.txt` to the `ib` directory and renames it as `test_copy.txt` +- If you want to copy a directory you need to use the `-r` (recursive) flag so that it recursively copies the contents of the directory as well (if you forget, it simply gives an error and reminds you to do it). For this command as well you can use the special path specifiers. - `cp dir/test.txt .`: copies `test.txt` from the `dir` to the current directory @@ -206,290 +138,151 @@ For this command as well you can use the special path specifiers. ## rm [ReMove] Deletes files/directories. -There shouldn't be any problem with using it if you are careful with what you -do (aka, don't just paste the first command you find on the Internet without -knowing what it does) but, if you feel more comfortable, you can always create -a command that moves the files to a Bin directory instead, and then you can use -rm inside it (see aliases in [Other interesting concepts to learn about](##Other interesting concepts to learn about)). +There shouldn't be any problem with using it if you are careful with what you do (aka, don't just paste the first command you find on the Internet without knowing what it does) but, if you feel more comfortable, you can always create a command that moves the files to a Bin directory instead, and then you can use rm inside it (see aliases in [Other interesting concepts to learn about](##Other interesting concepts to learn about)). - `rm `: removes the file -- `rmdir `: removes a directory but **only** if it's empty (useful if you - want to make sure all directories you are erasing have nothing left inside). -- `rm -r `: removes recursively (the directory and its contents). - Just like with `cp`, if you forget to put the `-r` the terminal will give an - error (directory isn't empty). If it is empty, it will tell you to use `rmdir` - but you can also use `rm -r`. +- `rmdir `: removes a directory but **only** if it's empty (useful if you want to make sure all directories you are erasing have nothing left inside). +- `rm -r `: removes recursively (the directory and its contents). Just like with `cp`, if you forget to put the `-r` the terminal will give an error (directory isn't empty). If it is empty, it will tell you to use `rmdir` but you can also use `rm -r`. ## nano -Simple terminal text editor. Because it works on the terminal, mouse support -isn't activated by default (but there is an option to use it though). This -means you need to use the arrow keys to move the cursor. +Simple terminal text editor. Because it works on the terminal, mouse support isn't activated by default (but there is an option to use it though). This means you need to use the arrow keys to move the cursor. - `nano `: opens a file to edit it. If it doesn't exists it creates it. -- **Ctrl+O**: saves the changes (capital O, not zero) and asks you what name you - want to use. If you don't want to save them to a new file, just hit enter. -- **Ctrl+X**: exists the editor (if you haven't saved it will prompt you to do - it). +- **Ctrl+O**: saves the changes (capital O, not zero) and asks you what name you want to use. If you don't want to save them to a new file, just hit enter. +- **Ctrl+X**: exists the editor (if you haven't saved it will prompt you to do it). There's a cheat sheet in the base of the editor with other useful keybindings. ## VS Code -If you use VS Code as you editor, you can launch it form the terminal (which is -useful when you are already in the directory you want to work on). +If you use VS Code as you editor, you can launch it form the terminal (which is useful when you are already in the directory you want to work on). - `code`: opens VS Code - `code `: opens the file in VS Code -- `code `: opens the directory in VS Code (if you are currently in it you - can use `code .`) +- `code `: opens the directory in VS Code (if you are currently in it you can use `code .`) ## file -In Linux, file extensions are only useful as a reference for the user, the -system ignores them and they don't have to really correspond to the real type -of the file or be there at all (they can be omitted). To check the type of a -file you can use the file command. +In Linux, file extensions are only useful as a reference for the user, the system ignores them and they don't have to really correspond to the real type of the file or be there at all (they can be omitted). To check the type of a file you can use the file command. - `file `: indicates the type of the file ## sudo -In Linux there exists a special user called root. This superuser has the -permissions to do almost anything in the computer and it would be the -equivalent of an administrator role. A user can have the permissions to execute -commands as root and there are two ways of doing it. The first one is to log in -as the superuser, which is dangerous because the computer will execute whatever -you ask for without thinking twice about it. The second option (recommended) is -writing `sudo` in front of the command you need to execute as root. The rest of -your commands will be executed with normal permissions. +In Linux there exists a special user called root. This superuser has the permissions to do almost anything in the computer and it would be the equivalent of an administrator role. A user can have the permissions to execute commands as root and there are two ways of doing it. The first one is to log in as the superuser, which is dangerous because the computer will execute whatever you ask for without thinking twice about it. The second option (recommended) is writing `sudo` in front of the command you need to execute as root. The rest of your commands will be executed with normal permissions. - `apt install` ---> `sudo apt install` - `rm file` ---> `sudo rm file` ## sudoedit -When you are going to edit a system file, instead of using `sudo` directory it's -recommendable to use `sudoedit`. +When you are going to edit a system file, instead of using `sudo` directory it's recommendable to use `sudoedit`. - `sudo ` ----> `sudoedit ` -The command opens the file using your default editor (you can change it by -adding the line `export VISUAL=` at the end of your `.bashrc` file in -your home) - -The first reason to use `sudoedit` is that it's safer. The command makes a copy -of the system file which the user can edit and, when you are finished making -changes to it, it writes them to the original file. Using `sudo`, the file is -opened by the superuser, who has permissions to execute whatever command or -delete that file or any other (in nano you can't, but if you use other editors -like vim, you can open terminals or execute commands from inside it and those -would be executed with root permissions). With `sudoedit`, everything will be -done as your user, so there are less probabilities that something goes terribly -wrong. - -The second and more practical reason is, as it's executed as your user and not -as root, the command uses your editor configuration. Again, maybe if you use -nano it doesn't make much of a difference, but if you have a more configurable -or extensible editor you can use your configuration when editing the system -files instead of having to stick with the root config (which will probably be -the default one). +The command opens the file using your default editor (you can change it by adding the line `export VISUAL=` at the end of your `.bashrc` file in your home) + +The first reason to use `sudoedit` is that it's safer. The command makes a copy of the system file which the user can edit and, when you are finished making changes to it, it writes them to the original file. Using `sudo`, the file is opened by the superuser, who has permissions to execute whatever command or delete that file or any other (in nano you can't, but if you use other editors like vim, you can open terminals or execute commands from inside it and those would be executed with root permissions). With `sudoedit`, everything will be done as your user, so there are less probabilities that something goes terribly wrong. + +The second and more practical reason is, as it's executed as your user and not as root, the command uses your editor configuration. Again, maybe if you use nano it doesn't make much of a difference, but if you have a more configurable or extensible editor you can use your configuration when editing the system files instead of having to stick with the root config (which will probably be the default one). ## Other commands -- `clear`: clears the terminal (erases everything written and brings the cursor - back to the top) +- `clear`: clears the terminal (erases everything written and brings the cursor back to the top) - `exit`: exists the terminal -- `find -name `: finds every file/directory inside `dir` that has the - name `name`. It has to be the exact name (unless you use wildcards) +- `find -name `: finds every file/directory inside `dir` that has the name `name`. It has to be the exact name (unless you use wildcards) - `history`: shows the history of commands -- `pwd` [Print Working Directory]: prints to the terminal the absolute path to - the directory you are currently in -- `less `: same as `cat`, it prints the contents of a text file, but less - allows you to scroll through them -- zoxide: alternative to `cd` that stores a list with your most visited - directories and jumps directly to the first one that matches the string you - give it (not installed by default) +- `pwd` [Print Working Directory]: prints to the terminal the absolute path to the directory you are currently in +- `less `: same as `cat`, it prints the contents of a text file, but less allows you to scroll through them +- zoxide: alternative to `cd` that stores a list with your most visited directories and jumps directly to the first one that matches the string you give it (not installed by default) - `z Doc`: could jump to `~/Documents` - `z screen `: could jump to `~/Desktop/pictures/screenshots` - `z shots `: could also jump to `~/Desktop/pictures/screenshots` -- `grep`: allows to search inside of files or in the output of a command (for - example, if ls has a big output and you want to see if there is some pdf, you - can use `grep` to search the ".pdf" string inside the output of `ls`). It's - recommended to learn about redirections beforehand, since they will be - specially useful here (in [Other interesting concepts to learn about](##Other interesting concepts to learn about)) +- `grep`: allows to search inside of files or in the output of a command (for example, if ls has a big output and you want to see if there is some pdf, you can use `grep` to search the ".pdf" string inside the output of `ls`). It's recommended to learn about redirections beforehand, since they will be specially useful here (in [Other interesting concepts to learn about](##Other interesting concepts to learn about)) - `grep `: prints all lines `file` that contain `string` - `grep -i `: the search is case insensitive -- `xkill`: if a window freezes and stops responding, you can execute `xkill` inside - a terminal and click with the mouse on the offending window to kill it. +- `xkill`: if a window freezes and stops responding, you can execute `xkill` inside a terminal and click with the mouse on the offending window to kill it. ## Other concepts -- To copy and paste, highlight the text to copy and press the mouse wheel to - paste it. You can also use Ctrl+Shift+C and Ctrl+Shift+V. +- To copy and paste, highlight the text to copy and press the mouse wheel to paste it. You can also use Ctrl+Shift+C and Ctrl+Shift+V. - To interrupt a command : Ctrl+C -- Up arrow to see previous commands (goes through the command history). It - allows you to execute them again or edit them. -- Tab autocompletes commands and file names. If there is more than one option, - pressing it twice shows all possibilities (pressing it once seems to do - nothing, that's when you know there are various options or none at all). Its - use is recommended, not only to type quicker but to make sure the - command/file exists and is correctly written (take into account that there - isn't autocompletion of parameters for all commands). +- Up arrow to see previous commands (goes through the command history). It allows you to execute them again or edit them. +- Tab autocompletes commands and file names. If there is more than one option, pressing it twice shows all possibilities (pressing it once seems to do nothing, that's when you know there are various options or none at all). Its use is recommended, not only to type quicker but to make sure the command/file exists and is correctly written (take into account that there isn't autocompletion of parameters for all commands). - `cd Do` [tab tab] > Documents/ \ Downloads/ \ Doc.txt -- Many commands have the option `-v` to make the output more [v]erbose - (outputs more information about what the command is doing) -- Instead of using the command `clear`, it's possible to clean the screen using - Ctrl+L. This has the added advantage that if you already have a command - written you don't need to erase it in order to clear the screen. -- Instead of using `exit` you can exit the terminal by pressing Ctrl+D. For - this you *do* need to have no input in the command line. +- Many commands have the option `-v` to make the output more [v]erbose (outputs more information about what the command is doing) +- Instead of using the command `clear`, it's possible to clean the screen using Ctrl+L. This has the added advantage that if you already have a command written you don't need to erase it in order to clear the screen. +- Instead of using `exit` you can exit the terminal by pressing Ctrl+D. For this you *do* need to have no input in the command line. ## The wildcard -In Linux, `*` represents the wildcard. It tells the terminal that it can -substitute the asterisk by anything, including nothing. If you tell it to move -to a directory every file with the name `*ing`, it will move the files "ing", -"programming", "editing"... because they all end in "ing", whatever goes before -doesn't matter (you have indicated it can be anything). However, the file -"programming.txt" will not be moved. To include it you would have to indicate -that it should also not care about what comes after "ing" (`*ing*`). - -Another example would be if you have the files "ing.pdf", "ing.txt", -"programming.txt" and "editing" and you just want to move the first two. For -this you would use `ing*`, indicating that the file has to start with "ing" and -whatever goes after doesn't matter. +In Linux, `*` represents the wildcard. It tells the terminal that it can substitute the asterisk by anything, including nothing. If you tell it to move to a directory every file with the name `*ing`, it will move the files "ing", "programming", "editing"... because they all end in "ing", whatever goes before doesn't matter (you have indicated it can be anything). However, the file "programming.txt" will not be moved. To include it you would have to indicate that it should also not care about what comes after "ing" (`*ing*`). + +Another example would be if you have the files "ing.pdf", "ing.txt", "programming.txt" and "editing" and you just want to move the first two. For this you would use `ing*`, indicating that the file has to start with "ing" and whatever goes after doesn't matter. This is very useful when you want to move al pdf files to a directory, for example: - `mv *.pdf pdf-dir/` : moves every file that ends in ".pdf" -(We have to remember that in Linux you don't need to have the appropriate -extension in every file, so this would move all files with a name ending in -pdf, not necessarily all pdf files. But if the conventions are followed, which -normally are, it should be the same in the end) +(We have to remember that in Linux you don't need to have the appropriate extension in every file, so this would move all files with a name ending in pdf, not necessarily all pdf files. But if the conventions are followed, which normally are, it should be the same in the end) -Correspondingly, if you have a bunch of files starting in the same way and want -to erase them all, you can write the start string and add `*`. -- `rm erasable*`: will erase "erasable_edited.pdf", "erasable_original.pdf", - "erasable.txt"... +Correspondingly, if you have a bunch of files starting in the same way and want to erase them all, you can write the start string and add `*`. +- `rm erasable*`: will erase "erasable_edited.pdf", "erasable_original.pdf", "erasable.txt"... -**BE VERY CAREFUL WHEN USING WILDCARDS, SPECIALLY WITH RM.** If written on its own -(`rm *`) it will erase everything in the directory (you are telling the system to -erase everything with any name). This can be very useful but also very -dangerous. +**BE VERY CAREFUL WHEN USING WILDCARDS, SPECIALLY WITH RM.** If written on its own (`rm *`) it will erase everything in the directory (you are telling the system to erase everything with any name). This can be very useful but also very dangerous. ## Help -- `apropos `: searches for `string` in the list of installed commands - (has the command name and a brief description). +- `apropos `: searches for `string` in the list of installed commands (has the command name and a brief description). - E.g.: `apropos editor` > ... \ nano (1) - Nano's ANOther text editor, inspired by Pico \ ... -- `man `: prints the command's [man]ual. Most commands (specially the - most used ones) have a manual page. However, sometimes it can be difficult to - understand, specially when you are starting. You press `Q` to exit the - command page and yes, there is a manual for the manual (`man man`). -- `--help`: many commands accept this parameter and print a shorter version of - the manual. -- `tldr` [Too Long Didn't Read] : instead of an extensive file about what the - command does and every single possible option it has, `tldr` just gives a - couple of examples of its most typical uses. The tldr pages are downloaded as - you access them, so it's possible you need access to the Internet and they - can take a bit to load if you haven't used it before. To avoid this you can - do `tldr --update`(tldr is not installed by default). -- `cheat`: allows the use of cheat sheets. You can install the ones premade by - the community (which is useful) but the most interesting thing about cheat is - that it allows you to create your own entries. This way you can write your - own cheat sheets as you go on learning new commands and parameters, to have - everything handy and not have to look it up from scratch again (this command - is not installed by default) +- `man `: prints the command's [man]ual. Most commands (specially the most used ones) have a manual page. However, sometimes it can be difficult to understand, specially when you are starting. You press `Q` to exit the command page and yes, there is a manual for the manual (`man man`). +- `--help`: many commands accept this parameter and print a shorter version of the manual. +- `tldr` [Too Long Didn't Read] : instead of an extensive file about what the command does and every single possible option it has, `tldr` just gives a couple of examples of its most typical uses. The tldr pages are downloaded as you access them, so it's possible you need access to the Internet and they can take a bit to load if you haven't used it before. To avoid this you can do `tldr --update`(tldr is not installed by default). +- `cheat`: allows the use of cheat sheets. You can install the ones premade by the community (which is useful) but the most interesting thing about cheat is that it allows you to create your own entries. This way you can write your own cheat sheets as you go on learning new commands and parameters, to have everything handy and not have to look it up from scratch again (this command is not installed by default) - `cheat `: prints the cheat sheet for `command` - - `cheat -e `: edits the cheat sheet for `command`. If it doesn't - exist it is created. - -My recommendation is: when you need to find a new command use `apropos` or the -Internet ("terminal how to edit text file", "terminal merge pdfs"). When you -know the command but need the parameters, use `tldr` or `cheat`. These tell you -what to write to get the desired result, but they don't explain you the -command. You can use `man` to search for the explanation for those parameters -(you search by pressing `/` [ex: `/-l` + Enter] and move between the results with `n` -and `N`). This way, you start to get comfortable with the manual without having -to depend completely on it. If all fails, the Internet is your friend. I'd -write down everything you learn on a text file, for future reference, or if -it's a specific example for a command inside a cheat cheat sheet. Sometimes it -takes a while to get the exact command you need and this saves you time the -next time you have to use it. + - `cheat -e `: edits the cheat sheet for `command`. If it doesn't exist it is created. + +My recommendation is: when you need to find a new command use `apropos` or the Internet ("terminal how to edit text file", "terminal merge pdfs"). When you know the command but need the parameters, use `tldr` or `cheat`. These tell you what to write to get the desired result, but they don't explain you the command. You can use `man` to search for the explanation for those parameters (you search by pressing `/` [ex: `/-l` + Enter] and move between the results with `n` and `N`). This way, you start to get comfortable with the manual without having to depend completely on it. If all fails, the Internet is your friend. I'd write down everything you learn on a text file, for future reference, or if it's a specific example for a command inside a cheat cheat sheet. Sometimes it takes a while to get the exact command you need and this saves you time the next time you have to use it. ## Useless comands everyone should know -They aren't installed by default and usually have a bunch of parameters and -options you can learn about in the help pages (`man`, `tldr`...). -- `cowsay `: prints a cow with a speech bubble that has `text` inside. With - the parameter `-f` you can change the ascii drawing (my favourite is the - stegosaurus with a hat) -- `sl`: animation of a train crossing your terminal. You can't stop it with - Ctrl+C (they used "sl" to nag everyone that mistypes `ls` so not being able to - stop it is on purpose). It has a couple of options, like people screaming for - help or making the train fly. +They aren't installed by default and usually have a bunch of parameters and options you can learn about in the help pages (`man`, `tldr`...). +- `cowsay `: prints a cow with a speech bubble that has `text` inside. With the parameter `-f` you can change the ascii drawing (my favourite is the stegosaurus with a hat) +- `sl`: animation of a train crossing your terminal. You can't stop it with Ctrl+C (they used "sl" to nag everyone that mistypes `ls` so not being able to stop it is on purpose). It has a couple of options, like people screaming for help or making the train fly. - `cmatrix`: characters falling through your terminal screen - `espeak`: text-to-speech -- `fortune`: prints a random fortune (like the ones from the cookies). You can - create your on fortune files and use them instead of or with the default ones - (it is also useful when you want a quick way of getting a random sentence - from a set of them) +- `fortune`: prints a random fortune (like the ones from the cookies). You can create your on fortune files and use them instead of or with the default ones (it is also useful when you want a quick way of getting a random sentence from a set of them) - `oneko`: renders a cat that follows your cursor through the screen. -- `xeyes`: a classic. Eyes that follow your cursor (if you use Wayland they won't - work correctly) +- `xeyes`: a classic. Eyes that follow your cursor (if you use Wayland they won't work correctly) - `toilet`/`figlet`: print asciiart text - `rig`: creates a random identity (name-surname and address) -- `xpenguins` and `xsnow`: might not work everywhere (even inside X11) but should - make a bunch of penguins appear and start moving through your screen (for the - first one) and snow fall from the top of your screen and on top of your - windows (for the second one). -- `lolcat`: prints multicoloured text. It's usually used with command redirection - (e.g.: `ls | lolcat`). -- `neofetch`/`fastfetch` (and others): print an ascii drawing of your distro's logo - (this can be changed) and your device specs (distro, desktop environment, - RAM, CPU...). Neofetch is he most typical one but it has been discontinued - and fastfetch is faster. Both can be personalized but neofetch has many - pre-designed themes. +- `xpenguins` and `xsnow`: might not work everywhere (even inside X11) but should make a bunch of penguins appear and start moving through your screen (for the first one) and snow fall from the top of your screen and on top of your windows (for the second one). +- `lolcat`: prints multicoloured text. It's usually used with command redirection (e.g.: `ls | lolcat`). +- `neofetch`/`fastfetch` (and others): print an ascii drawing of your distro's logo (this can be changed) and your device specs (distro, desktop environment, RAM, CPU...). Neofetch is he most typical one but it has been discontinued and fastfetch is faster. Both can be personalized but neofetch has many pre-designed themes. - NeoCat (neofetch themes): https://github.com/m3tozz/NeoCat - Neofetch-themes: https://github.com/Chick2D/neofetch-themes/tree/main ## Other interesting concepts to learn about -- Package manager: the most practical way of installing packages in Linux. - Depending on the distro you will use one manager or another but the important - thing is to learn the commands to update/upgrade the system and install, - remove and search packages. -- Redirection: allows the concatenation of commands, redirecting the output of - one to the input of the next one or to a file. +- Package manager: the most practical way of installing packages in Linux. Depending on the distro you will use one manager or another but the important thing is to learn the commands to update/upgrade the system and install, remove and search packages. +- Redirection: allows the concatenation of commands, redirecting the output of one to the input of the next one or to a file. https://www.freecodecamp.org/news/linux-terminal-piping-and-redirection-guide/ -- Alias: you can create an alias for a command to give it a different name (so - you can write `potato` instead of `sudo`) or to simplify certain combinations of - parameters that you use a lot (`ll` instead of `ls -lh`). +- Alias: you can create an alias for a command to give it a different name (so you can write `potato` instead of `sudo`) or to simplify certain combinations of parameters that you use a lot (`ll` instead of `ls -lh`). https://www.freecodecamp.org/news/how-to-add-aliases-to-terminal-commands/ - (in most distros you don't need to touch the `.bashrc`. If you create a - `.bash_aliases` file in your home directory it detects it automatically. This - allows you to have an alias-specific file, cleaner and more concise). -- Automation: terminal scripts allow to automate many things and cron is also - very useful for this, allowing to execute commands at certain hours/days - automatically. + (in most distros you don't need to touch the `.bashrc`. If you create a `.bash_aliases` file in your home directory it detects it automatically. This allows you to have an alias-specific file, cleaner and more concise). +- Automation: terminal scripts allow to automate many things and cron is also very useful for this, allowing to execute commands at certain hours/days automatically. - Bash Scripting Tutorial: https://ryanstutorials.net/bash-scripting-tutorial/ - Understanding Crontab in Linux with Examples: https://linuxhandbook.com/crontab/ -- zsh: bash is the default shell for many distros but there are others. One of - the better known is zsh, due to its ample functionality and configurability, - like syntax highlighting in the command line. It's usually installed - alongside ohmyzsh, which allows to easily configure it and install - extensions. +- zsh: bash is the default shell for many distros but there are others. One of the better known is zsh, due to its ample functionality and configurability, like syntax highlighting in the command line. It's usually installed alongside ohmyzsh, which allows to easily configure it and install extensions. - ohmyzsh web page: https://ohmyz.sh/ - ohmyzsh GitHub: https://github.com/ohmyzsh/ohmyzsh -- `hollywood`: just some Hollywood-hacking magic (just keep pressing Ctrl+C to - exit it) +- `hollywood`: some Hollywood-hacking magic (just keep pressing Ctrl+C to exit it) ## Other resources -Some useful resources to learn how to use the terminal and Linux in general. -I haven't looked at them all and they aren't in any particular order. +Some useful resources to learn how to use the terminal and Linux in general. I haven't looked at them all and they aren't in any particular order. #### Tools/documentation: -- Explain Shell: you write a command and it explains what each part does (not - perfect but it can help) https://explainshell.com/ +- Explain Shell: you write a command and it explains what each part does (not perfect but it can help) + https://explainshell.com/ #### Courses -- Linux Journey: web page to learn the Linux basics https://linuxjourney.com/ +- Linux Journey: web page to learn the Linux basics + https://linuxjourney.com/ - Beginner's Guide to the Bash Terminal (video): https://www.youtube.com/watch?v=oxuRxtrO2Ag - The Linux Command Line (book): https://www.linuxcommand.org/ @@ -499,8 +292,10 @@ I haven't looked at them all and they aren't in any particular order. https://web.mit.edu/mprat/Public/web/Terminus/Web/main.html - Learning Terminal in Linux (video series): https://www.youtube.com/playlist?list=PLc7fktTRMBozYfi4zlDeH0IdLdGImeOnO -- Linux Tutorial: https://ryanstutorials.net/linuxtutorial/ -- The Unix Shell: https://swcarpentry.github.io/shell-novice/ +- Linux Tutorial: + https://ryanstutorials.net/linuxtutorial/ +- The Unix Shell: + https://swcarpentry.github.io/shell-novice/ #### Articles - Command Line for Beginners - How to Use the Terminal Like a Pro: @@ -511,13 +306,18 @@ I haven't looked at them all and they aren't in any particular order. #### Interesting blogs - ItsFOSS: News and tutorials about the free software world in general: https://itsfoss.com/ -- Linux Handbook: Linux courses and tutorials: https://linuxhandbook.com/ +- Linux Handbook: Linux courses and tutorials: + https://linuxhandbook.com/ - FreeCodeCamp: articles and courses about computers science in general: https://www.freecodecamp.org/ -- LinuxOPsys: linux tutorials and tips: https://linuxopsys.com/ +- LinuxOPsys: linux tutorials and tips: + https://linuxopsys.com/ #### YouTube channels -- Learn Linux TV: https://www.youtube.com/@LearnLinuxTV/videos -- Veronica Explains: https://www.youtube.com/@VeronicaExplains/videos -- The Linux Experiment (Linux news): https://www.youtube.com/@TheLinuxEXP/videos +- Learn Linux TV: + https://www.youtube.com/@LearnLinuxTV/videos +- Veronica Explains: + https://www.youtube.com/@VeronicaExplains/videos +- The Linux Experiment (Linux news): + https://www.youtube.com/@TheLinuxEXP/videos From 789bb147327064699f220e793d77e911a7c5137c Mon Sep 17 00:00:00 2001 From: P-15 Date: Tue, 10 Dec 2024 12:05:37 +0100 Subject: [PATCH 04/11] Fix html not rendring lists correctly --- .../intro_terminal_v3_en.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/content/docs/educational_resources/intro_terminal_v3_en.md b/content/docs/educational_resources/intro_terminal_v3_en.md index 7f94ab9..01f3ed3 100644 --- a/content/docs/educational_resources/intro_terminal_v3_en.md +++ b/content/docs/educational_resources/intro_terminal_v3_en.md @@ -16,16 +16,19 @@ In Linux the file system has a tree structure and all files and directories are under the root directory, represented as `/` (the root of the tree). For example, the user's home directory is in the path `/home`, which means inside the directory "home" which is inside the directory "/" (root). There are two types of paths, absolute and relative. + - Absolute paths always start at root and indicate how to reach a file or directory from there. They work independently of where you are in the file system at the moment. When a path starts with `/` it's **always** absolute and the system will start at the root of the file tree. - Relative paths depend on the directory in which you are located in that moment, so they can't be used from any place. The system follows the "directions" of the path starting at the directory you are currently on. Example: + - `/home/my_usr/Desktop/dir1/file.txt` - `dir1/file.txt` Both paths go to the same file, but for the second example you have to be located in the Desktop directory for it to work and it doesn't begin with `/` because its relative, and only absolute paths (like the first one) begin with `/`. It's advisable to use absolute paths for scripts so that they can be executed from any directory without giving error. There's a series of "special directories" that can be used in paths: + - `..` : it indicates the previous/parent directory. If you move to `..` from `Desktop/dir`, you will end up in `Desktop`. - `.` : it indicates your current directory. It's useful when you want to copy a file to where you are (copy file to `.`) - `~` : it indicates your home directory (`/home/my_usr`). It's the directory in which you start when you open a terminal. The paths that use it are a bit different from relative and absolute paths until now. It is relative to the user (if you are logged in into another account it won't work) but inside the user directory, it could be said to be absolute, as it doesn't matter in which directory you are (`~/Desktop/dir1` works even if you are inside `/home/my_usr/Documents/dir2`) @@ -37,6 +40,7 @@ https://linuxhandbook.com/linux-directory-structure/ Lists the files (and subdirectories) in a directory (same as looking at them in the graphical file manager). The contents of a directory are printed in different colours, which normally are: + - **White:** files - **Bold blue:** directories (folders) - **Bold green:** executable files (if it's not green it doesn't necessarily mean that file is not meant to be executed, it just means you don't have the permissions to do it) @@ -79,6 +83,7 @@ Creates a directory. ## cat Prints the contents of a text file to the terminal. + - `cat ` - `cat -n `: prints the file with numbered lines @@ -95,18 +100,21 @@ Moves/renames files and directories. #### Moving You specify the file (or files) you want to move and the destination (which has to be common for all files). + - `mv ` - `mv test.txt ib`: moves the file `test.txt` to the directory `ib` - `mv dir ib`: moves the directory `dir` to the directory `ib` - `mv test.txt dir ib`: moves file `test.txt` and directory `dir` to `ib` You can use the path modifiers: + - `mv file ..`: moves the file to the parent directory **Warning: If the destination doesn't exists and there is only one file/directory to move, it will rename it (to the destination name). If there is more than one file/directory to move, it will just give an error.** #### Renaming You specify the file you want to rename and the new name. + - `mv ` - `mv fle.txt file.txt`: renames file `fle.txt` to `file.txt` - `mv dir dir1`: renames directory `dir` to `dir1` @@ -116,6 +124,7 @@ You specify the file you want to rename and the new name. #### Combining both You can combine the move and rename operations: + - `mv dir/file file1`: moves file to the current directory (`./file1`) and renames it to `file1` - `mv file dir/file1`: moves `file` to the directory `dir` and renames it as `file1` - `mv dir/dir1 dir2`: moves `dir1` to the current directory and renames it as `dir2` @@ -132,6 +141,7 @@ Copies files/directories (can automatically rename the copy) - If you want to copy a directory you need to use the `-r` (recursive) flag so that it recursively copies the contents of the directory as well (if you forget, it simply gives an error and reminds you to do it). For this command as well you can use the special path specifiers. + - `cp dir/test.txt .`: copies `test.txt` from the `dir` to the current directory - `cp file ..`: copies the file to the parent directory @@ -154,6 +164,7 @@ There's a cheat sheet in the base of the editor with other useful keybindings. ## VS Code If you use VS Code as you editor, you can launch it form the terminal (which is useful when you are already in the directory you want to work on). + - `code`: opens VS Code - `code `: opens the file in VS Code - `code `: opens the directory in VS Code (if you are currently in it you can use `code .`) @@ -181,6 +192,7 @@ The first reason to use `sudoedit` is that it's safer. The command makes a copy The second and more practical reason is, as it's executed as your user and not as root, the command uses your editor configuration. Again, maybe if you use nano it doesn't make much of a difference, but if you have a more configurable or extensible editor you can use your configuration when editing the system files instead of having to stick with the root config (which will probably be the default one). ## Other commands + - `clear`: clears the terminal (erases everything written and brings the cursor back to the top) - `exit`: exists the terminal - `find -name `: finds every file/directory inside `dir` that has the name `name`. It has to be the exact name (unless you use wildcards) @@ -197,6 +209,7 @@ The second and more practical reason is, as it's executed as your user and not a - `xkill`: if a window freezes and stops responding, you can execute `xkill` inside a terminal and click with the mouse on the offending window to kill it. ## Other concepts + - To copy and paste, highlight the text to copy and press the mouse wheel to paste it. You can also use Ctrl+Shift+C and Ctrl+Shift+V. - To interrupt a command : Ctrl+C - Up arrow to see previous commands (goes through the command history). It allows you to execute them again or edit them. @@ -215,15 +228,18 @@ In Linux, `*` represents the wildcard. It tells the terminal that it can substit Another example would be if you have the files "ing.pdf", "ing.txt", "programming.txt" and "editing" and you just want to move the first two. For this you would use `ing*`, indicating that the file has to start with "ing" and whatever goes after doesn't matter. This is very useful when you want to move al pdf files to a directory, for example: + - `mv *.pdf pdf-dir/` : moves every file that ends in ".pdf" (We have to remember that in Linux you don't need to have the appropriate extension in every file, so this would move all files with a name ending in pdf, not necessarily all pdf files. But if the conventions are followed, which normally are, it should be the same in the end) Correspondingly, if you have a bunch of files starting in the same way and want to erase them all, you can write the start string and add `*`. + - `rm erasable*`: will erase "erasable_edited.pdf", "erasable_original.pdf", "erasable.txt"... **BE VERY CAREFUL WHEN USING WILDCARDS, SPECIALLY WITH RM.** If written on its own (`rm *`) it will erase everything in the directory (you are telling the system to erase everything with any name). This can be very useful but also very dangerous. ## Help + - `apropos `: searches for `string` in the list of installed commands (has the command name and a brief description). - E.g.: `apropos editor` > ... \ @@ -240,6 +256,7 @@ My recommendation is: when you need to find a new command use `apropos` or the I ## Useless comands everyone should know They aren't installed by default and usually have a bunch of parameters and options you can learn about in the help pages (`man`, `tldr`...). + - `cowsay `: prints a cow with a speech bubble that has `text` inside. With the parameter `-f` you can change the ascii drawing (my favourite is the stegosaurus with a hat) - `sl`: animation of a train crossing your terminal. You can't stop it with Ctrl+C (they used "sl" to nag everyone that mistypes `ls` so not being able to stop it is on purpose). It has a couple of options, like people screaming for help or making the train fly. - `cmatrix`: characters falling through your terminal screen @@ -257,6 +274,7 @@ They aren't installed by default and usually have a bunch of parameters and opti ## Other interesting concepts to learn about + - Package manager: the most practical way of installing packages in Linux. Depending on the distro you will use one manager or another but the important thing is to learn the commands to update/upgrade the system and install, remove and search packages. - Redirection: allows the concatenation of commands, redirecting the output of one to the input of the next one or to a file. https://www.freecodecamp.org/news/linux-terminal-piping-and-redirection-guide/ @@ -277,10 +295,12 @@ They aren't installed by default and usually have a bunch of parameters and opti Some useful resources to learn how to use the terminal and Linux in general. I haven't looked at them all and they aren't in any particular order. #### Tools/documentation: + - Explain Shell: you write a command and it explains what each part does (not perfect but it can help) https://explainshell.com/ #### Courses + - Linux Journey: web page to learn the Linux basics https://linuxjourney.com/ - Beginner's Guide to the Bash Terminal (video): @@ -298,12 +318,14 @@ Some useful resources to learn how to use the terminal and Linux in general. I h https://swcarpentry.github.io/shell-novice/ #### Articles + - Command Line for Beginners - How to Use the Terminal Like a Pro: https://www.freecodecamp.org/news/command-line-for-beginners/ - How to Type Less and Work Faster in the Linux Terminal: https://www.howtogeek.com/815219/how-to-work-faster-in-linux-terminal/ #### Interesting blogs + - ItsFOSS: News and tutorials about the free software world in general: https://itsfoss.com/ - Linux Handbook: Linux courses and tutorials: @@ -314,6 +336,7 @@ Some useful resources to learn how to use the terminal and Linux in general. I h https://linuxopsys.com/ #### YouTube channels + - Learn Linux TV: https://www.youtube.com/@LearnLinuxTV/videos - Veronica Explains: From 0513c88cd317930cef3e7760f38969b62ac41b59 Mon Sep 17 00:00:00 2001 From: P-15 Date: Tue, 10 Dec 2024 12:12:55 +0100 Subject: [PATCH 05/11] Add links to urls --- .../intro_terminal_v3_en.md | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/content/docs/educational_resources/intro_terminal_v3_en.md b/content/docs/educational_resources/intro_terminal_v3_en.md index 01f3ed3..86cd0df 100644 --- a/content/docs/educational_resources/intro_terminal_v3_en.md +++ b/content/docs/educational_resources/intro_terminal_v3_en.md @@ -34,7 +34,7 @@ There's a series of "special directories" that can be used in paths: - `~` : it indicates your home directory (`/home/my_usr`). It's the directory in which you start when you open a terminal. The paths that use it are a bit different from relative and absolute paths until now. It is relative to the user (if you are logged in into another account it won't work) but inside the user directory, it could be said to be absolute, as it doesn't matter in which directory you are (`~/Desktop/dir1` works even if you are inside `/home/my_usr/Documents/dir2`) For more information about the structure of the Linux file system you can read -https://linuxhandbook.com/linux-directory-structure/ + ## ls [LiSt] Lists the files (and subdirectories) in a directory (same as looking at them in the graphical file manager). @@ -148,7 +148,7 @@ For this command as well you can use the special path specifiers. ## rm [ReMove] Deletes files/directories. -There shouldn't be any problem with using it if you are careful with what you do (aka, don't just paste the first command you find on the Internet without knowing what it does) but, if you feel more comfortable, you can always create a command that moves the files to a Bin directory instead, and then you can use rm inside it (see aliases in [Other interesting concepts to learn about](##Other interesting concepts to learn about)). +There shouldn't be any problem with using it if you are careful with what you do (aka, don't just paste the first command you find on the Internet without knowing what it does) but, if you feel more comfortable, you can always create a command that moves the files to a Bin directory instead, and then you can use rm inside it (see aliases in [Other interesting concepts to learn about](#other-interesting-concepts-to-learn-about)). - `rm `: removes the file - `rmdir `: removes a directory but **only** if it's empty (useful if you want to make sure all directories you are erasing have nothing left inside). @@ -203,7 +203,7 @@ The second and more practical reason is, as it's executed as your user and not a - `z Doc`: could jump to `~/Documents` - `z screen `: could jump to `~/Desktop/pictures/screenshots` - `z shots `: could also jump to `~/Desktop/pictures/screenshots` -- `grep`: allows to search inside of files or in the output of a command (for example, if ls has a big output and you want to see if there is some pdf, you can use `grep` to search the ".pdf" string inside the output of `ls`). It's recommended to learn about redirections beforehand, since they will be specially useful here (in [Other interesting concepts to learn about](##Other interesting concepts to learn about)) +- `grep`: allows to search inside of files or in the output of a command (for example, if ls has a big output and you want to see if there is some pdf, you can use `grep` to search the ".pdf" string inside the output of `ls`). It's recommended to learn about redirections beforehand, since they will be specially useful here (in [Other interesting concepts to learn about](#other-interesting-concepts-to-learn-about)) - `grep `: prints all lines `file` that contain `string` - `grep -i `: the search is case insensitive - `xkill`: if a window freezes and stops responding, you can execute `xkill` inside a terminal and click with the mouse on the offending window to kill it. @@ -269,26 +269,26 @@ They aren't installed by default and usually have a bunch of parameters and opti - `xpenguins` and `xsnow`: might not work everywhere (even inside X11) but should make a bunch of penguins appear and start moving through your screen (for the first one) and snow fall from the top of your screen and on top of your windows (for the second one). - `lolcat`: prints multicoloured text. It's usually used with command redirection (e.g.: `ls | lolcat`). - `neofetch`/`fastfetch` (and others): print an ascii drawing of your distro's logo (this can be changed) and your device specs (distro, desktop environment, RAM, CPU...). Neofetch is he most typical one but it has been discontinued and fastfetch is faster. Both can be personalized but neofetch has many pre-designed themes. - - NeoCat (neofetch themes): https://github.com/m3tozz/NeoCat - - Neofetch-themes: https://github.com/Chick2D/neofetch-themes/tree/main + - NeoCat (neofetch themes): + - Neofetch-themes: ## Other interesting concepts to learn about - Package manager: the most practical way of installing packages in Linux. Depending on the distro you will use one manager or another but the important thing is to learn the commands to update/upgrade the system and install, remove and search packages. - Redirection: allows the concatenation of commands, redirecting the output of one to the input of the next one or to a file. - https://www.freecodecamp.org/news/linux-terminal-piping-and-redirection-guide/ + - Alias: you can create an alias for a command to give it a different name (so you can write `potato` instead of `sudo`) or to simplify certain combinations of parameters that you use a lot (`ll` instead of `ls -lh`). - https://www.freecodecamp.org/news/how-to-add-aliases-to-terminal-commands/ + (in most distros you don't need to touch the `.bashrc`. If you create a `.bash_aliases` file in your home directory it detects it automatically. This allows you to have an alias-specific file, cleaner and more concise). - Automation: terminal scripts allow to automate many things and cron is also very useful for this, allowing to execute commands at certain hours/days automatically. - Bash Scripting Tutorial: - https://ryanstutorials.net/bash-scripting-tutorial/ + - Understanding Crontab in Linux with Examples: - https://linuxhandbook.com/crontab/ + - zsh: bash is the default shell for many distros but there are others. One of the better known is zsh, due to its ample functionality and configurability, like syntax highlighting in the command line. It's usually installed alongside ohmyzsh, which allows to easily configure it and install extensions. - - ohmyzsh web page: https://ohmyz.sh/ - - ohmyzsh GitHub: https://github.com/ohmyzsh/ohmyzsh + - ohmyzsh web page: + - ohmyzsh GitHub: - `hollywood`: some Hollywood-hacking magic (just keep pressing Ctrl+C to exit it) ## Other resources @@ -297,50 +297,50 @@ Some useful resources to learn how to use the terminal and Linux in general. I h #### Tools/documentation: - Explain Shell: you write a command and it explains what each part does (not perfect but it can help) - https://explainshell.com/ + #### Courses - Linux Journey: web page to learn the Linux basics - https://linuxjourney.com/ + - Beginner's Guide to the Bash Terminal (video): - https://www.youtube.com/watch?v=oxuRxtrO2Ag + - The Linux Command Line (book): https://www.linuxcommand.org/ - Linux Terminal - Getting Started! (video series): - https://www.youtube.com/watch?v=b5NmtmNwMgU&list=PLW5y1tjAOzI2ZYTlMdGzCV8AJuoqW5lKB + - Text adventure game using the terminal commands (video game): - https://web.mit.edu/mprat/Public/web/Terminus/Web/main.html + - Learning Terminal in Linux (video series): - https://www.youtube.com/playlist?list=PLc7fktTRMBozYfi4zlDeH0IdLdGImeOnO + - Linux Tutorial: - https://ryanstutorials.net/linuxtutorial/ + - The Unix Shell: - https://swcarpentry.github.io/shell-novice/ + #### Articles - Command Line for Beginners - How to Use the Terminal Like a Pro: - https://www.freecodecamp.org/news/command-line-for-beginners/ + - How to Type Less and Work Faster in the Linux Terminal: - https://www.howtogeek.com/815219/how-to-work-faster-in-linux-terminal/ + #### Interesting blogs - ItsFOSS: News and tutorials about the free software world in general: - https://itsfoss.com/ + - Linux Handbook: Linux courses and tutorials: - https://linuxhandbook.com/ + - FreeCodeCamp: articles and courses about computers science in general: - https://www.freecodecamp.org/ + - LinuxOPsys: linux tutorials and tips: - https://linuxopsys.com/ + #### YouTube channels - Learn Linux TV: - https://www.youtube.com/@LearnLinuxTV/videos + - Veronica Explains: - https://www.youtube.com/@VeronicaExplains/videos + - The Linux Experiment (Linux news): - https://www.youtube.com/@TheLinuxEXP/videos + From 289990990edf1d3d4ab8903506632bf6e02aa500 Mon Sep 17 00:00:00 2001 From: P-15 Date: Tue, 10 Dec 2024 22:54:13 +0100 Subject: [PATCH 06/11] Format files the zola way --- content/docs/educational_resources/_index.md | 8 ++++++++ .../{intro_terminal_v3_en.md => terminal-intro.md} | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 content/docs/educational_resources/_index.md rename content/docs/educational_resources/{intro_terminal_v3_en.md => terminal-intro.md} (99%) diff --git a/content/docs/educational_resources/_index.md b/content/docs/educational_resources/_index.md new file mode 100644 index 0000000..e1ddeda --- /dev/null +++ b/content/docs/educational_resources/_index.md @@ -0,0 +1,8 @@ ++++ +title = "Educational resources" +description = "Beginner tutorials and educational material" +template = "docs/section.html" +sort_by = "weight" +weight = 1 +draft = false ++++ diff --git a/content/docs/educational_resources/intro_terminal_v3_en.md b/content/docs/educational_resources/terminal-intro.md similarity index 99% rename from content/docs/educational_resources/intro_terminal_v3_en.md rename to content/docs/educational_resources/terminal-intro.md index 86cd0df..3885dd4 100644 --- a/content/docs/educational_resources/intro_terminal_v3_en.md +++ b/content/docs/educational_resources/terminal-intro.md @@ -1,4 +1,12 @@ -# Terminal introduction ++++ +title = "Terminal Introduction" +description = "Tutorial to help you get started with the terminal" +template = "docs/page.html" +sort_by = "weight" +weight = 2 +draft = false ++++ + ## Intro - To open a terminal in most Linux distributions you can use `Ctrl+Atl+T` (if it doesn't work, you can try with `Atl+Enter`, `Alt+T`, `Ctrl+T` or something like that or just look for it in the app launcher) - What is between `<>` has to be substituted and the "<>" are removed. From ba6ec6bd237ac06a23bfeb4a90e91fee6b95a206 Mon Sep 17 00:00:00 2001 From: simsine Date: Wed, 1 Jan 2025 14:59:50 +0100 Subject: [PATCH 07/11] Update ny-vm.md --- content/docs/instrukser/ny-vm.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/docs/instrukser/ny-vm.md b/content/docs/instrukser/ny-vm.md index 0799701..f77f8a4 100644 --- a/content/docs/instrukser/ny-vm.md +++ b/content/docs/instrukser/ny-vm.md @@ -20,6 +20,7 @@ before starting. The setup can be found [here](../ha-setup) `1000 (VM 1000)` på Fergus (høyreklikk -> clone) 1. Definer navn, gjerne navn på kunde 1. Velg en ledig VM-ID +1. Sett mode til full clone 1. Sett target storage til `basseng` 1. Klikk "Clone" 1. Brukernavn: fribyte From a5c5a5d42ec5ca18617c759ff5cee37b7a47ef5e Mon Sep 17 00:00:00 2001 From: simsine Date: Fri, 3 Jan 2025 20:10:50 +0100 Subject: [PATCH 08/11] Update nettverk-oversikt.md --- content/docs/nettverk/nettverk-oversikt.md | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/content/docs/nettverk/nettverk-oversikt.md b/content/docs/nettverk/nettverk-oversikt.md index ad45fed..ff1f8a3 100644 --- a/content/docs/nettverk/nettverk-oversikt.md +++ b/content/docs/nettverk/nettverk-oversikt.md @@ -95,22 +95,22 @@ draft = false This uses the subnet `10.0.0.0/24` for local adresses -| IPV4 | IPV6 | Name | Interface | Comment | -| --------- | ---- | --------------- | ---------------------- | -------------------- | -| 10.0.0.1 | | fw-1 (netti) | bge0 | LAN interface fw-1 | -| 10.0.0.2 | | fw-2 | bge0 | Lan interface fw-2 | -| 10.0.0.11 | | Gateway NAT | | Opnsense LAN gateway | -| 10.0.0.20 | | Letti | enp130s0f0 | Letti Proxmox Host | -| 10.0.0.21 | | Netti | enp132s0f0 | Netti Proxmox Host | -| 10.0.0.25 | | Pluto | enp7s0f1 | Netti Proxmox Host | -| 10.0.0.26 | | Fergus | enp7s0f1 | Netti Proxmox Host | -| 10.0.0.27 | | Skaftetrynet | eno1 | Netti Proxmox Host | -| 10.0.0.70 | | Raptus | vmbrNAT (pluto) | k3s Master | -| 10.0.0.71 | | Petter | vmbrNAT (Fergus) | k3s Master | -| 10.0.0.72 | | Hutre | vmbrNAT (Skaftetrynet) | k3s Master | -| 10.0.0.80 | | Lille-Hjelper-1 | vmbrNAT (Pluto) | k3s Slave | -| 10.0.0.81 | | Lille-Hjelper-2 | vmbrNAT (Fergus) | k3s Slave | -| 10.0.0.82 | | Lille-Hjelper-3 | vmbrNAT (Skaftetrynet) | k3s Slave | -| | | | | | -| | | | | | -| | | | | | +| IPV4 | IPV6 | Name | Interface | Comment | +| ---------- | ---- | --------------- | ---------------------- | -------------------- | +| 10.0.0.1 | | fw-1 (netti) | bge0 | LAN interface fw-1 | +| 10.0.0.2 | | fw-2 | bge0 | Lan interface fw-2 | +| 10.0.0.11 | | Gateway NAT | | Opnsense LAN gateway | +| 10.0.0.20 | | Letti | enp130s0f0 | Letti Proxmox Host | +| 10.0.0.21 | | Netti | enp132s0f0 | Netti Proxmox Host | +| 10.0.0.25 | | Pluto | enp7s0f1 | Netti Proxmox Host | +| 10.0.0.26 | | Fergus | enp7s0f1 | Netti Proxmox Host | +| 10.0.0.27 | | Skaftetrynet | eno1 | Netti Proxmox Host | +| 10.0.0.70 | | Raptus | vmbrNAT (pluto) | k3s Master | +| 10.0.0.71 | | Petter | vmbrNAT (Fergus) | k3s Master | +| 10.0.0.72 | | Hutre | vmbrNAT (Skaftetrynet) | k3s Master | +| 10.0.0.80 | | Lille-Hjelper-1 | vmbrNAT (Pluto) | k3s Slave | +| 10.0.0.81 | | Lille-Hjelper-2 | vmbrNAT (Fergus) | k3s Slave | +| 10.0.0.82 | | Lille-Hjelper-3 | vmbrNAT (Skaftetrynet) | k3s Slave | +| 10.0.0.100 | | lb-1 | | | +| 10.0.0.101 | | lb-2 | | | +| | | | | | From 58a69661fb7f5f7f9df52e96289c50189fef80ca Mon Sep 17 00:00:00 2001 From: simsine Date: Fri, 3 Jan 2025 20:45:54 +0100 Subject: [PATCH 09/11] Update nettverk-oversikt.md --- content/docs/nettverk/nettverk-oversikt.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/docs/nettverk/nettverk-oversikt.md b/content/docs/nettverk/nettverk-oversikt.md index ff1f8a3..7e2de42 100644 --- a/content/docs/nettverk/nettverk-oversikt.md +++ b/content/docs/nettverk/nettverk-oversikt.md @@ -93,12 +93,12 @@ draft = false # New network (OpnSense NAT) -This uses the subnet `10.0.0.0/24` for local adresses +This local network uses the subnet `10.0.0.0/24` for 254 total local adresses -| IPV4 | IPV6 | Name | Interface | Comment | +|IPV4 (1-254)| IPV6 | Name | Interface | Comment | | ---------- | ---- | --------------- | ---------------------- | -------------------- | | 10.0.0.1 | | fw-1 (netti) | bge0 | LAN interface fw-1 | -| 10.0.0.2 | | fw-2 | bge0 | Lan interface fw-2 | +| 10.0.0.2 | | fw-2 (letti) | bge0 | Lan interface fw-2 | | 10.0.0.11 | | Gateway NAT | | Opnsense LAN gateway | | 10.0.0.20 | | Letti | enp130s0f0 | Letti Proxmox Host | | 10.0.0.21 | | Netti | enp132s0f0 | Netti Proxmox Host | @@ -111,6 +111,6 @@ This uses the subnet `10.0.0.0/24` for local adresses | 10.0.0.80 | | Lille-Hjelper-1 | vmbrNAT (Pluto) | k3s Slave | | 10.0.0.81 | | Lille-Hjelper-2 | vmbrNAT (Fergus) | k3s Slave | | 10.0.0.82 | | Lille-Hjelper-3 | vmbrNAT (Skaftetrynet) | k3s Slave | -| 10.0.0.100 | | lb-1 | | | -| 10.0.0.101 | | lb-2 | | | +| 10.0.0.100 | | lb-1 (netti) | vmbrNAT (netti) | NAT tcp proxy | +| 10.0.0.101 | | lb-2 (letti) | vmbrNAT (letti) | NAT tcp proxy | | | | | | | From e545d05c4bcceb303cad65efca1686e8e38a4995 Mon Sep 17 00:00:00 2001 From: polsevev Date: Tue, 7 Jan 2025 18:55:46 +0100 Subject: [PATCH 10/11] Update new VM instructions --- content/docs/instrukser/ha_setup.md | 6 ++- content/docs/instrukser/ny-vm.md | 22 ++++++----- content/docs/instrukser/tailscale-setup.md | 43 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 content/docs/instrukser/tailscale-setup.md diff --git a/content/docs/instrukser/ha_setup.md b/content/docs/instrukser/ha_setup.md index 4c908e9..d53a6d1 100644 --- a/content/docs/instrukser/ha_setup.md +++ b/content/docs/instrukser/ha_setup.md @@ -11,7 +11,7 @@ weight = 3 First, in order to set up HA, you need to have the VM hosted on one of the following servers: -- Bolivar +- Fergus - Skaftetrynet - Pluto @@ -26,7 +26,8 @@ Other than that, the setup for creating a vm is the same as can be found of the VM is stored on the pool "basseng"** 2. Create a Replication job, this can be found under the `Replication` tab within the Proxmox UI after clicking the VM. - - Set the target to be the current server + - You need to create two of these, each pointing to one of the other servers + - Set the target to one of the other servers - Schedule: \*/15 (replication every 15 minutes, this will only transfer changes so won't bog the network) - Enabled checked @@ -34,6 +35,7 @@ Other than that, the setup for creating a vm is the same as can be found 3. Navigate to the `Datacenter` tab found in the top of the tree structure found on the left. Then click on `HA` 4. Then fill it in as follows: + - Group: Main - VM: Select the VM you want to enable HA for - The rest default 5. After all these steps are complete, replication is now set up! diff --git a/content/docs/instrukser/ny-vm.md b/content/docs/instrukser/ny-vm.md index f77f8a4..2d52aa8 100644 --- a/content/docs/instrukser/ny-vm.md +++ b/content/docs/instrukser/ny-vm.md @@ -12,10 +12,10 @@ draft = false If this VM is meant to have High availability, please read the setup for that before starting. The setup can be found [here](../ha-setup) -1. Koble til wireguard -1. Gå til proxmox [https://10.100.10.1:8006](https://10.100.10.1:8006) +1. Koble til tailscale +1. Gå til proxmox + [https://pluto.vpn.fribyte.no:8006](https://pluto.vpn.fribyte.no:8006) alternativt: - [https://proxmox.fribyte.no:8006](https://proxmox.fribyte.no:8006) 1. Clone templaten `6000 (Clone me ubuntu)` på Skaftetrynet eller `1000 (VM 1000)` på Fergus (høyreklikk -> clone) 1. Definer navn, gjerne navn på kunde @@ -42,13 +42,17 @@ before starting. The setup can be found [here](../ha-setup) 1. Start vm og vent på at den er klar. Se progress ved å trykke på `Console` og se at den booter. -- Det er ofte problemer på dette steget, fordi template man kopierer fra ikke - virker som den skal. Spør gjerne om hjelp her. + - Det er ofte problemer på dette steget, fordi template man kopierer fra ikke + virker som den skal. Spør gjerne om hjelp her. -1. Legg gjerne inn en DNS peker på DNS slik at man kan bruke - `ssh fribyte@maskinnavn.fribyte.no`. -1. Du skal nå kunne `ssh` inn til den via skaftetrynet med `ssh {ip-addresse}` - eller `ssh {definert-navn}` +1. Registrer serveren i tailscale nettverket vårt. Dette kan du se her: + [/docs/instrukser/tailscale](/docs/instrukser/tailscale) + +## Registrer VMen i HA + +Dersom denne VMen er kritisk for kunde, bør den registreres i High Availibility +i clusteret vårt. Dette kan du se +[/docs/instrukser/ha-setup](/docs/instrukser/ha-setup) ## Tildel mer lagringsplass diff --git a/content/docs/instrukser/tailscale-setup.md b/content/docs/instrukser/tailscale-setup.md new file mode 100644 index 0000000..4d41096 --- /dev/null +++ b/content/docs/instrukser/tailscale-setup.md @@ -0,0 +1,43 @@ ++++ +title = "Ny VM Tailscale" +description = "Koble ny VM til tailscale nettet" +template = "docs/page.html" +sort_by = "weight" +weight = 5 +draft = false ++++ + +## How to connect a new VM to the tailscale network so we can ssh to it + +1. Install tailscale following their official guide + - [https://tailscale.com/download](https://tailscale.com/download) +1. Then connect to the tailscale mesh VPN by running this command + + ``` + sudo tailscale up --login-server https://headscale.fribyte.no --ssh --accept-dns=false + ``` + +1. Then you want to copy the key from the output, it should look something like + follows + + ``` + mkey:27d04d3c1c5e9........ + ``` + +1. Then while keeping that terminal active, ssh into the headscale VM + + ``` + ssh fribyte@headscale + ``` + +1. Then run this command where NAME=name of VM and the `mkey:cccfdsdsfds.....` + + ``` + sudo ~/join.sh + ``` + +1. Check that the VM is accessible over tailscale by running + + ``` + ssh fribyte@ + ``` From 3c0f2b8e9fd3d7af4aa1fb94716ddd707c0e87d1 Mon Sep 17 00:00:00 2001 From: polsevev Date: Tue, 7 Jan 2025 18:57:39 +0100 Subject: [PATCH 11/11] Updated tailscale install on VM --- content/docs/instrukser/tailscale-setup.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/content/docs/instrukser/tailscale-setup.md b/content/docs/instrukser/tailscale-setup.md index 4d41096..1ee3dc8 100644 --- a/content/docs/instrukser/tailscale-setup.md +++ b/content/docs/instrukser/tailscale-setup.md @@ -41,3 +41,15 @@ draft = false ``` ssh fribyte@ ``` + +## Empty output + +If for some reason you get an empty output when running `tailscale up` you can +get it from the journal log of the headscale VM. This can be seen with the +command + +``` +sudo journalctl -xeu headscale.service +``` + +It should be within one of the last log entries