Added Wiki for Linux Proxmox and div. Software-installs

This commit is contained in:
ZennDev1337 2023-12-21 13:00:56 +01:00
parent d47f1dc602
commit 741584446c
17 changed files with 4537 additions and 0 deletions

132
Linux/Dotfiles-sync-git.md Normal file
View file

@ -0,0 +1,132 @@
## Kompletter Neueinstieg
Wenn du deine Konfigurationen noch nicht in einem Git-Repository verfolgt hast, kannst diese Technik einfach mit diesen Zeilen verwenden:
```
git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
```
- Die erste Zeile erstellt den Ordner `~/.cfg`, der ein [Git-Bare-Repository](http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/) ist, das unsere Dateien verfolgt.
- Dann erstellen wir eine Alias-`config`, die wir anstelle des regulären `git` verwenden, wenn wir mit unserem Konfigurations-Repository interagieren möchten.
- Wir setzen lokal für das Repository ein Flag, um Dateien auszublenden, die wir noch nicht explizit verfolgen. Auf diese Weise werden Dateien, die du nicht verfolgen möchtest, nicht als `nicht verfolgt` angezeigt, wenn du später `config status` und andere Befehle eingibst.
- Du kannst die Aliasdefinition auch von Hand zu deiner `.bashrc` hinzufügen oder die vierte Zeile verwenden, die der Einfachheit halber zur Verfügung gestellt wird.
Ich habe die obigen Zeilen in ein [Snippet](https://bitbucket.org/snippets/nicolapaolucci/ergX9) in Bitbucket gepackt und über eine kurze URL verlinkt. Auf diese Weise kannst du hiermit deine Einrichtung vornehmen:
```
curl -Lks http://bit.do/cfg-init | /bin/bash
```
Nachdem du die Einrichtung ausgeführt hast, kann jede Datei im `$HOME-Ordner` mit normalen Befehlen versioniert werden, wobei `git` durch deinen neu erstellten `config`-Alias ersetzt wird, wie z. B.:
```
config status
config add .vimrc
config commit -m "Add vimrc"
config add .bashrc
config commit -m "Add bashrc"
config push
```
## Installation deiner Punktdateien auf einem neuen System (oder Migration zu diesem Setup)
Wenn du deine Konfigurations-/Punktdateien bereits in einem [Git-Repository](https://www.atlassian.com/de/git) aufbewahrst, kannst du auf einem neuen System mit den folgenden Schritten zu dieser Einrichtung migrieren:
- Vergewissere dich vor der Installation, dass du den Alias für deine `.bashrc` oder `.zsh` committet hast:
```
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
```
- Dein Quell-Repository muss den Ordner ignorieren, in dem du es klonen wirst, damit keine seltsamen Rekursionsprobleme verursacht werden:
```
echo ".cfg" >> .gitignore
```
- Klone nun deine Punktdateien in ein [Bare](http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/)-Repository in einem "_Punkt_"-Ordner deines `$HOME`:
```
git clone --bare <git-repo-url> $HOME/.cfg
```
- Definiere den Alias im aktuellen Shell-Bereich:
```
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
```
- Checke den eigentlichen Inhalt aus dem Bare-Repository in deinen `$HOME`-Ordner aus:
```
config checkout
```
- Der obige Schritt schlägt möglicherweise mit einer Meldung wie folgt fehl:
```
error: The following untracked working tree files would be overwritten by checkout:
    .bashrc
    .gitignore
Please move or remove them before you can switch branches.
Aborting
```
Dies liegt daran, dass dein `$HOME`-Ordner möglicherweise bereits einige Standardkonfigurationsdateien enthält, die von Git überschrieben würden. Die Lösung ist einfach: Sichere die Dateien, wenn sie dir wichtig sind, und entferne sie, wenn sie nicht von Bedeutung sind. Mit dem folgenden Shortcut kannst du alle störenden Dateien automatisch in einen Sicherungsordner verschieben:
```
mkdir -p .config-backup &&\
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} |\
xargs -I{} mv {} .config-backup/{}
```
- Führe das Auschecken erneut durch, wenn du Probleme hattest:
```
config checkout
```
- Setze das Flag `showUntrackedFiles` in diesem spezifischen (lokalen) Repository auf `no`:
```
config config --local status.showUntrackedFiles no
```
- Nun bist du fertig und kannst ab jetzt `config`-Befehle eingeben, um deine Punktdateien hinzuzufügen und zu aktualisieren:
```
config status
config add .vimrc
config commit -m "Add vimrc"
config add .bashrc
config commit -m "Add bashrc"
config push
```
Um dich nicht an all diese Schritte erinnern zu müssen, wenn du einen neuen Rechner einrichten möchtest, kannst du ein einfaches Skript erstellen, es wie ich [als Bitbucket-Snippet speichern](https://bitbucket.org/snippets/nicolapaolucci/7rE9K), [eine kurze URL dafür erstellen](http://bit.do/) und es so aufrufen:
```
curl -Lks http://bit.do/cfg-install | /bin/bash
```
Der Vollständigkeit halber habe ich das gemacht (getestet auf vielen frischgebackenen [Alpine Linux-Containern](http://www.alpinelinux.org/)):
```
git clone --bare https://bitbucket.org/durdn/cfg.git $HOME/.cfg
function config {
   /usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
mkdir -p .config-backup
config checkout
if [ $? = 0 ]; then
  echo "Checked out config.";
  else
    echo "Backing up pre-existing dot files.";
    config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{}
fi;
config checkout
config config status.showUntrackedFiles no
```

122
Linux/Git.md Normal file
View file

@ -0,0 +1,122 @@
# Git Basic commands
Neue Files werden mit `git add .` gestasht somit sind diese in der Que um hochgeladen zu werden. Alle files aus der `.gitignore` file werden dabei ignoriert.
```
git add .
```
Wir können einen neuen Commit mit `git commit -m " "` erstellen in den Anführungszeichen, kommt die Message bzw. der Kommentar hin.
```
git commit -m "Commit Message"
```
Wenn du nicht spezifische files in einen Commit staschen willst sondern alle geänderten files commiten willst kannst du damit alles adden und commiten:
```
git commit -am "Commit Message"
```
Um deine Commits in den Remote zu laden:
```
git push -u origin [master/main] # bzw. BranchName anstelle von Master/Main
```
Um deinen Lokalen Master/Main auf den neusten Stand zu bringen verwende:
```
git pull origin [master/main]
```
Um den neusten Commit zu löschen verwende:
```
git reset HEAD~1
```
## Branches
Neue Remote Branches können mit git fetch geladen werden.
```
git fetch --all
```
Um eine Lokale Branch zu erstellen kannst du folgenden command verwenden:
```
git checkout -b <branch-name>
```
Um diese Branch auch im Remote Origin zu erstellen benutze:
```
git push --set-upstream origin branch-name
```
Um eine Lokale Branch zu löschen kannst du folgenden command verwenden:
```
git branch -d <branch-name>
```
Mit git switch kannst du direkt auf eine Branch einen checkout machen welche nur im remote existiert.
```
git switch <existing-branch-name> # Checkout und fetch einer bestehenden Branch im Remote
git switch -c <non-existing-branch-name> # Erstellt eine neue Branch
```
## Git Merge
Um die neusten updates in deine Branch zu fetchen kannst du folgende commands ausführen:
```
git checkout yourWorkingBranch # Moved dich in deine Branch
git fetch origin # Updated deine Origin Branch
git merge origin/[master/main] # Update deiner branch mit dem Master/Main
```
# Git init neue Repo
Um ein neues repo zu erstellen, benutzen wir Lokal git init.
```
git init
```
Damit wird der .git folder erstellt.\
Wir erstellen jetzt die Main Branch welche wir auch in unserem Remote haben werden.
```
git branch -M main
```
Wir müssen nun ein Remote hinzufügen. Dies ist mit folgendem command möglich:
```
git remote add origin git@github.com:[DeinUsername]/DeinProjektName.git
```
Jetzt können wir unseren ersten Commit Pushen damit das Projekt ersteinmal auf dem Remote ist.
```
git add .
git commit -m "first commit"
git push -u origin main
```
# Git Config
```
git config --global user.name "YOUR_USERNAME"
git config --global user.email "im_satoshi@musk.com"
git config --global --list # Um deine Infos zu überprüfen
```
# Upload / Sync 2 Repos
<https://www.opentechguides.com/how-to/article/git/177/git-sync-repos.html>

583
Linux/Grep.md Normal file
View file

@ -0,0 +1,583 @@
# Using Grep & Regular Expressions to Search for Text Patterns in Linux
## Introduction
The `grep` command is one of the most useful commands in a Linux terminal environment. The name `grep` stands for "global regular expression print". This means that you can use `grep` to check whether the input it receives matches a specified pattern. This seemingly trivial program is extremely powerful; its ability to sort input based on complex rules makes it a popular link in many command chains.
In this tutorial, you will explore the `grep` command's options, and then you'll dive into using regular expressions to do more advanced searching.
## Prerequisites
To follow along with this guide, you will need access to a computer running a Linux-based operating system. This can either be a virtual private server which you've connected to with SSH or your local machine. Note that this tutorial was validated using a Linux server running Ubuntu 20.04, but the examples given should work on a computer running any version of any Linux distribution.
If you plan to use a remote server to follow this guide, we encourage you to first complete our [Initial Server Setup guide](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04). Doing so will set you up with a secure server environment --- including a non-**root** user with `sudo` privileges and a firewall configured with UFW --- which you can use to build your Linux skills.
## Basic Usage
In this tutorial, you'll use `grep` to search the [GNU General Public License version 3](https://www.gnu.org/licenses/gpl-3.0.en.html) for various words and phrases.
If you're on an Ubuntu system, you can find the file in the `/usr/share/common-licenses` folder. Copy it to your home directory:
```
cp /usr/share/common-licenses/GPL-3 .
```
If you're on another system, use the `curl` command to download a copy:
```
curl -o GPL-3 https://www.gnu.org/licenses/gpl-3.0.txt
```
You'll also use the BSD license file in this tutorial. On Linux, you can copy that to your home directory with the following command:
```
cp /usr/share/common-licenses/BSD .
```
If you're on another system, create the file with the following command:
```
cat << 'EOF' > BSD
Copyright (c) The Regents of the University of California.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1\. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2\. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3\. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
EOF
```
Now that you have the files, you can start working with `grep`.
In the most basic form, you use `grep` to match literal patterns within a text file. This means that if you pass `grep` a word to search for, it will print out every line in the file containing that word.
Execute the following command to use `grep` to search for every line that contains the word `GNU`:
```
grep "GNU" GPL-3
```
The first argument, `GNU`, is the pattern you're searching for, while the second argument, `GPL-3`, is the input file you wish to search.
The resulting output will be every line containing the pattern text:
```
Output
GNU GENERAL PUBLIC LICENSE
The GNU General Public License is a free, copyleft license for
the GNU General Public License is intended to guarantee your freedom to
GNU General Public License for most of our software; it applies also to
Developers that use the GNU GPL protect your rights with two steps:
"This License" refers to version 3 of the GNU General Public License.
13. Use with the GNU Affero General Public License.
under version 3 of the GNU Affero General Public License into a single
...
...
```
On some systems, the pattern you searched for will be highlighted in the output.
### Common Options
By default, `grep` will search for the exact specified pattern within the input file and return the lines it finds. You can make this behavior more useful though by adding some optional flags to `grep`.
If you want `grep` to ignore the "case" of your search parameter and search for both upper- and lower-case variations, you can specify the `-i` or `--ignore-case` option.
Search for each instance of the word `license` (with upper, lower, or mixed cases) in the same file as before with the following command:
```
grep -i "license" GPL-3
```
The results contain: `LICENSE`, `license`, and `License`:
```
Output
GNU GENERAL PUBLIC LICENSE
of this license document, but changing it is not allowed.
The GNU General Public License is a free, copyleft license for
The licenses for most software and other practical works are designed
the GNU General Public License is intended to guarantee your freedom to
GNU General Public License for most of our software; it applies also to
price. Our General Public Licenses are designed to make sure that you
(1) assert copyright on the software, and (2) offer you this License
"This License" refers to version 3 of the GNU General Public License.
"The Program" refers to any copyrightable work licensed under this
...
...
```
If there was an instance with `LiCeNsE`, that would have been returned as well.
If you want to find all lines that **do not** contain a specified pattern, you can use the `-v` or `--invert-match` option.
Search for every line that does not contain the word `the` in the BSD license with the following command:
```
grep -v "the" BSD
```
You'll receive this output:
```
Output
All rights reserved.
Redistribution and use in source and binary forms, with or without
are met:
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
...
...
```
Since you did not specify the "ignore case" option, the last two items were returned as not having the word `the`.
It is often useful to know the line number that the matches occur on. You can do this by using the `-n` or `--line-number` option. Re-run the previous example with this flag added:
```
grep -vn "the" BSD
```
This will return the following text:
```
Output
2:All rights reserved.
3:
4:Redistribution and use in source and binary forms, with or without
6:are met:
13: may be used to endorse or promote products derived from this software
14: without specific prior written permission.
15:
16:THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17:ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
...
...
```
Now you can reference the line number if you want to make changes to every line that does not contain `the`. This is especially handy when working with source code.
## Regular Expressions
In the introduction, you learned that `grep` stands for "global regular expression print". A "regular expression" is a text string that describes a particular search pattern.
Different applications and programming languages implement regular expressions slightly differently. In this tutorial you will only be exploring a small subset of the way that `grep` describes its patterns.
### Literal Matches
In the previous examples in this tutorial, when you searched for the words `GNU` and `the`, you were actually searching for basic regular expressions which matched the exact string of characters `GNU` and `the`. Patterns that exactly specify the characters to be matched are called "literals" because they match the pattern literally, character-for-character.
It is helpful to think of these as matching a string of characters rather than matching a word. This will become a more important distinction as you learn more complex patterns.
All alphabetical and numerical characters (as well as certain other characters) are matched literally unless modified by other expression mechanisms.
### Anchor Matches
Anchors are special characters that specify where in the line a match must occur to be valid.
For instance, using anchors, you can specify that you only want to know about the lines that match `GNU` at the very beginning of the line. To do this, you could use the `^` anchor before the literal string.
Run the following command to search the `GPL-3` file and find lines where `GNU` occurs at the very beginning of a line:
```
grep "^GNU" GPL-3
```
This command will return the following two lines:
```
Output
GNU General Public License for most of our software; it applies also to
GNU General Public License, you may choose any version ever published
```
Similarly, you use the `$` anchor at the end of a pattern to indicate that the match will only be valid if it occurs at the very end of a line.
This command will match every line ending with the word `and` in the `GPL-3` file:
```
grep "and$" GPL-3
```
You'll receive this output:
```
Output
that there is no warranty for this free software. For both users' and
The precise terms and conditions for copying, distribution and
License. Each licensee is addressed as "you". "Licensees" and
receive it, in any medium, provided that you conspicuously and
alternative is allowed only occasionally and noncommercially, and
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
provisionally, unless and until the copyright holder explicitly and
receives a license from the original licensors, to run, modify and
make, use, sell, offer for sale, import and otherwise run, modify and
```
### Matching Any Character
The period character (.) is used in regular expressions to mean that any single character can exist at the specified location.
For example, to match anything in the `GPL-3` file that has two characters and then the string `cept`, you would use the following pattern:
```
grep "..cept" GPL-3
```
This command returns the following output:
```
Output
use, which is precisely where it is most unacceptable. Therefore, we
infringement under applicable copyright law, except executing it on a
tells the user that there is no warranty for the work (except to the
License by making exceptions from one or more of its conditions.
form of a separately written license, or stated as exceptions;
You may not propagate or modify a covered work except as expressly
9. Acceptance Not Required for Having Copies.
...
...
```
This output has instances of both `accept` and `except` and variations of the two words. The pattern would also have matched `z2cept` if that was found as well.
### Bracket Expressions
By placing a group of characters within brackets (`\[` and `\]`), you can specify that the character at that position can be any one character found within the bracket group.
For example, to find the lines that contain `too` or `two`, you would specify those variations succinctly by using the following pattern:
```
grep "t[wo]o" GPL-3
```
The output shows that both variations exist in the file:
```
Output
your programs, too.
freedoms that you received. You must make sure that they, too, receive
Developers that use the GNU GPL protect your rights with two steps:
a computer network, with no transfer of a copy, is not conveying.
System Libraries, or general-purpose tools or generally available free
Corresponding Source from a network server at no charge.
...
...
```
Bracket notation gives you some interesting options. You can have the pattern match anything **except** the characters within a bracket by beginning the list of characters within the brackets with a `^` character.
This example is like the pattern `.ode`, but will not match the pattern `code`:
```
grep "[^c]ode" GPL-3
```
Here's the output you'll receive:
```
Output
1\. Source Code.
model, to give anyone who possesses the object code either (1) a
the only significant mode of use of the product.
notice like this when it starts in an interactive mode:
```
Notice that in the second line returned, there is, in fact, the word `code`. This is not a failure of the regular expression or grep. Rather, this line was returned because earlier in the line, the pattern `mode`, found within the word `model`, was found. The line was returned because there was an instance that matched the pattern.
Another helpful feature of brackets is that you can specify a range of characters instead of individually typing every available character.
This means that if you want to find every line that begins with a capital letter, you can use the following pattern:
```
grep "^[A-Z]" GPL-3
```
Here's the output this expression returns:
```
Output
GNU General Public License for most of our software; it applies also to
States should not allow patents to restrict development and use of
License. Each licensee is addressed as "you". "Licensees" and
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
System Libraries, or general-purpose tools or generally available free
Source.
User Product is transferred to the recipient in perpetuity or for a
...
...
```
Due to some legacy sorting issues, it is often more accurate to use POSIX character classes instead of character ranges like you just used.
To discuss every POSIX character class would be beyond the scope of this guide, but an example that would accomplish the same procedure as the previous example uses the `\[:upper:\]` character class within a bracket selector:
```
grep "^[[:upper:]]" GPL-3
```
The output will be the same as before.
### Repeat Pattern Zero or More Times
Finally, one of the most commonly used meta-characters is the asterisk, or `*`, which means "repeat the previous character or expression zero or more times".
To find each line in the `GPL-3` file that contains an opening and closing parenthesis, with only letters and single spaces in between, use the following expression:
```
grep "([A-Za-z ]*)" GPL-3
```
You'll get the following output:
```
Output
Copyright (C) 2007 Free Software Foundation, Inc.
distribution (with or without modification), making available to the
than the work as a whole, that (a) is included in the normal form of
Component, and (b) serves only to enable use of the work with that
(if any) on which the executable work runs, or a compiler used to
(including a physical distribution medium), accompanied by the
(including a physical distribution medium), accompanied by a
place (gratis or for a charge), and offer equivalent access to the
...
...
```
So far you've used periods, asterisks, and other characters in your expressions, but sometimes you need to search for those characters specifically.
### Escaping Meta-Characters
There are times where you'll need to search for a literal period or a literal opening bracket, especially when working with source code or configuration files. Because these characters have special meaning in regular expressions, you need to "escape" these characters to tell `grep` that you do not wish to use their special meaning in this case.
You escape characters by using the backslash character (`\`) in front of the character that would normally have a special meaning.
For instance, to find any line that begins with a capital letter and ends with a period, use the following expression which escapes the ending period so that it represents a literal period instead of the usual "any character" meaning:
```
grep "^[A-Z].*\.$" GPL-3
```
This is the output you'll see:
```
Output
Source.
License by making exceptions from one or more of its conditions.
License would be to refrain entirely from conveying the Program.
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
SUCH DAMAGES.
Also add information on how to contact you by electronic and paper mail.
```
Now let's look at other regular expression options.
## Extended Regular Expressions
The `grep` command supports a more extensive regular expression language by using the `-E` flag or by calling the `egrep` command instead of `grep`.
These options open up the capabilities of "extended regular expressions". Extended regular expressions include all of the basic meta-characters, along with additional meta-characters to express more complex matches.
### Grouping
One of the most useful abilities that extended regular expressions open up is the ability to group expressions together to manipulate or reference as one unit.
To group expressions together, wrap them in parentheses. If you would like to use parentheses without using extended regular expressions, you can escape them with the backslash to enable this functionality. This means that the following three expressions are functionally equivalent:
```
grep "\(grouping\)" file.txt
grep -E "(grouping)" file.txt
egrep "(grouping)" file.txt
```
### Alternation
Similar to how bracket expressions can specify different possible choices for single character matches, alternation allows you to specify alternative matches for strings or expression sets.
To indicate alternation, use the pipe character `|`. These are often used within parenthetical grouping to specify that one of two or more possibilities should be considered a match.
The following will find either `GPL` or `General Public License` in the text:
```
grep -E "(GPL|General Public License)" GPL-3
```
The output looks like this:
```
Output
The GNU General Public License is a free, copyleft license for
the GNU General Public License is intended to guarantee your freedom to
GNU General Public License for most of our software; it applies also to
price. Our General Public Licenses are designed to make sure that you
Developers that use the GNU GPL protect your rights with two steps:
For the developers' and authors' protection, the GPL clearly explains
authors' sake, the GPL requires that modified versions be marked as
have designed this version of the GPL to prohibit the practice for those
...
...
```
Alternation can select between more than two choices by adding additional choices within the selection group separated by additional pipe (`|`) characters.
### Quantifiers
Like the `*` meta-character that matched the previous character or character set zero or more times, there are other meta-characters available in extended regular expressions that specify the number of occurrences.
To match a character zero or one times, you can use the `?` character. This makes character or character sets that came before optional, in essence.
The following matches `copyright` and `right` by putting `copy` in an optional group:
```
grep -E "(copy)?right" GPL-3
```
You'll receive this output:
```
Output
Copyright (C) 2007 Free Software Foundation, Inc.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
"Copyright" also means copyright-like laws that apply to other kinds of
...
```
The `+` character matches an expression one or more times. This is almost like the `*` meta-character, but with the `+` character, the expression **must** match at least once.
The following expression matches the string `free` plus one or more characters that are not white space characters:
```
grep -E "free[^[:space:]]+" GPL-3
```
You'll see this output:
```
Output
The GNU General Public License is a free, copyleft license for
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
When we speak of free software, we are referring to freedom, not
have the freedom to distribute copies of free software (and charge for
you modify it: responsibilities to respect the freedom of others.
freedomss that you received. You must make sure that they, too, receive
protecting users' freedom to change the software. The systematic
of the GPL, as needed to protect the freedom of users.
patents cannot be used to render the program non-free.
```
### Specifying Match Repetition
To specify the number of times that a match is repeated, use the brace characters (`{` and `}`). These characters let you specify an exact number, a range, or an upper or lower bounds to the amount of times an expression can match.
Use the following expression to find all of the lines in the `GPL-3` file that contain triple-vowels:
```
grep -E "[AEIOUaeiou]{3}" GPL-3
```
Each line returned has a word with three vowels:
```
Output
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
receive it, in any medium, provided that you conspicuously and
give under the previous paragraph, plus a right to possession of the
covered work so as to satisfy simultaneously your obligations under this
```
To match any words that have between 16 and 20 characters, use the following expression:
```
grep -E "[[:alpha:]]{16,20}" GPL-3
```
Here's this command's output:
```
Output
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
c) Prohibiting misrepresentation of the origin of that material, or
```
Only lines containing words within that length are displayed.
## Conclusion
`grep` is useful in finding patterns within files or within the file system hierarchy, so it's worth spending time getting comfortable with its options and syntax.
Regular expressions are even more versatile, and can be used with many popular programs. For instance, many text editors implement regular expressions for searching and replacing text.
Furthermore, most modern programming languages use regular expressions to perform procedures on specific pieces of data. Once you understand regular expressions, you'll be able to transfer that knowledge to many common computer-related tasks, from performing advanced searches in your text editor to validating user input.

36
Linux/Qemu.md Normal file
View file

@ -0,0 +1,36 @@
# QEMU install
install these packages
```
qemu virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat
```
start the services
edit this file
```
/etc/libvirt/libvirtd.conf
```
for windows you need also the Virt IO Driver
<https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.215-2/>
for windows delete 2 lines in the xml config
```
<timer name="rtc" tickpolicy="catchup"/>
<timer name="pit" tickpolicy="delay"/>
```
and put this on yes
```
<timer name="hpet" present="no"/>
```

16
Linux/SSH.md Normal file
View file

@ -0,0 +1,16 @@
# SSH Key erstellen
The algorithm is selected using the -t option and key size using the -b option. The following commands illustrate:
```
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519
```
To upload a public key to a server use the following command:
```
ssh-copy-id -i ~/.ssh/id_rsa.pub YOUR_USER_NAME@IP_ADDRESS_OF_THE_SERVER
```

661
Linux/UFW-Essentials.md Normal file
View file

@ -0,0 +1,661 @@
# UFW Essentials: Common Firewall Rules and Commands
## Introduction
UFW (**u**ncomplicated **f**ire**w**all) is a firewall configuration tool that runs on top of `iptables`, included by default within Ubuntu distributions. It provides a streamlined interface for configuring common firewall use cases via the command line.
This cheat sheet-style guide provides a quick reference to common UFW use cases and commands, including examples of how to allow and block services by port, network interface, and source IP address.
### How To Use This Guide
- This guide is in cheat sheet format with self-contained command-line snippets.
- Jump to any section that is relevant to the task you are trying to complete.
- When you see highlighted text in this guide's commands, keep in mind that this text should refer to IP addresses from your own network.
Remember that you can check your current UFW ruleset with `sudo ufw status` or `sudo ufw status verbose`.
## Verify UFW Status
To check if `ufw` is enabled, run:
```
sudo ufw status
```
```
Output
Status: inactive
```
The output will indicate if your firewall is active or not.
## Enable UFW
If you got a `Status: inactive` message when running `ufw status`, it means the firewall is not yet enabled on the system. You'll need to run a command to enable it.
By default, when enabled UFW will block external access to all ports on a server. In practice, that means if you are connected to a server via SSH and enable `ufw` before allowing access via the SSH port, you'll be disconnected. Make sure you follow the section on [how to enable SSH access](https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands) of this guide before enabling the firewall if that's your case.
To enable UFW on your system, run:
```
sudo ufw enable
```
You'll see output like this:
```
Output
Firewall is active and enabled on system startup
```
To see what is currently blocked or allowed, you may use the `verbose` parameter when running `ufw status`, as follows:
```
sudo ufw status
```
```
Output
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), deny (routed)
New profiles: skip
```
## Disable UFW
If for some reason you need to disable UFW, you can do so with the following command:
```
sudo ufw disable
```
Be aware that this command will fully disable the firewall service on your system.
## Block an IP Address
To block all network connections that originate from a specific IP address, run the following command, replacing the highlighted IP address with the IP address that you want to block:
```
sudo ufw deny from 203.0.113.100
```
```
Output
Rule added
```
In this example, `from 203.0.113.100` specifies a **source** IP address of "203.0.113.100".
If you run `sudo ufw status` now, you'll see the specified IP address listed as denied:
```
Output
Status: active
To Action From
-- ------ ----
Anywhere DENY 203.0.113.100
```
All connections, coming in or going out, are blocked for the specified IP address.
### Block a Subnet
If you need to block a full subnet, you may use the subnet address as `from` parameter on the `ufw deny` command. This would block all IP addresses in the example subnet `203.0.113.0/24`:
```
sudo ufw deny from 203.0.113.0/24
```
```
Output
Rule added
```
## Block Incoming Connections to a Network Interface
To block incoming connections from a specific IP address to a specific network interface, run the following command, replacing the highlighted IP address with the IP address you want to block:
```
sudo ufw deny in on eth0 from 203.0.113.100
```
```
Output
Rule added
```
The `in` parameter tells `ufw` to apply the rule only for **incoming** connections, and the `on eth0` parameter specifies that the rule applies only for the `eth0` interface. This might be useful if you have a system with several network interfaces (including virtual ones) and you need to block external access to some of these interfaces, but not all.
## Allow an IP Address
To allow all network connections that originate from a specific IP address, run the following command, replacing the highlighted IP address with the IP address that you want to allow access:
```
sudo ufw allow from 203.0.113.101
```
```
Output
Rule added
```
If you run `sudo ufw status` now, you'll see output similar to this, showing the word `ALLOW` next to the IP address you just added.
```
Output
Status: active
To Action From
-- ------ ----
...
Anywhere ALLOW 203.0.113.101
```
You can also allow connections from a whole subnet by providing the corresponding subnet mask for a host, such as `203.0.113.0/24`.
## Allow Incoming Connections to a Network Interface
To allow incoming connections from a specific IP address to a specific network interface, run the following command, replacing the highlighted IP address with the IP address you want to allow:
```
sudo ufw allow in on eth0 from 203.0.113.102
```
```
Output
Rule added
```
The `in` parameter tells `ufw` to apply the rule only for **incoming** connections, and the `on eth0` parameter specifies that the rule applies only for the `eth0` interface.
If you run `sudo ufw status` now, you'll see output similar to this:
```
Output
Status: active
To Action From
-- ------ ----
...
Anywhere on eth0 ALLOW 203.0.113.102
```
## Delete UFW Rule
To delete a rule that you previously set up within UFW, use `ufw delete` followed by the rule (`allow` or `deny`) and the target specification. The following example would delete a rule previously set to allow all connections from an IP address of `203.0.113.101`:
```
sudo ufw delete allow from 203.0.113.101
```
```
Output
Rule deleted
```
Another way to specify which rule you want to delete is by providing the rule ID. This information can be obtained with the following command:
```
sudo ufw status numbered
```
```
Output
Status: active
To Action From
-- ------ ----
[ 1] Anywhere DENY IN 203.0.113.100
[ 2] Anywhere on eth0 ALLOW IN 203.0.113.102
```
From the output, you can see that there are two active rules. The first rule, with highlighted values, denies all connections coming from the IP address `203.0.113.100`. The second rule allows connections on the `eth0` interface coming in from the IP address `203.0.113.102`.
Because by default UFW already blocks all external access unless explicitly allowed, the first rule is redundant, so you can remove it. To delete a rule by its ID, run:
```
sudo ufw delete 1
```
You will be prompted to confirm the operation and to make sure the ID you're providing refers to the correct rule you want to delete.
```
Output
Deleting:
deny from 203.0.113.100
Proceed with operation (y|n)? y
Rule deleted
```
If you list your rules again with `sudo ufw status`, you'll see that the rule was removed.
## List Available Application Profiles
Upon installation, applications that rely on network communications will typically set up a UFW profile that you can use to allow connection from external addresses. This is often the same as running `ufw allow from`, with the advantage of providing a shortcut that abstracts the specific port numbers a service uses and provides a user-friendly nomenclature to referenced services.
To list which profiles are currently available, run the following:
```
sudo ufw app list
```
If you installed a service such as a web server or other network-dependent software and a profile was not made available within UFW, first make sure the service is enabled. For remote servers, you'll typically have OpenSSH readily available:
```
Output
Available applications:
OpenSSH
```
## Enable Application Profile
To enable a UFW application profile, run `ufw allow` followed by the name of the application profile you want to enable, which you can obtain with a `sudo ufw app list` command. In the following example, we're enabling the OpenSSH profile, which will allow all incoming SSH connections on the default SSH port.
```
sudo ufw allow "OpenSSH"
```
```
Output
Rule added
Rule added (v6)
```
Remember to quote profile names that consist of multiple words, such as `Nginx HTTPS`.
## Disable Application Profile
To disable an application profile that you had previously set up within UFW, you'll need to remove its corresponding rule. For example, consider the following output from `sudo ufw status`:
```
sudo ufw status
```
```
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
```
This output indicates that the `Nginx Full` application profile is currently enabled, allowing any and all connections to the web server both via HTTP as well as via HTTPS. If you'd want to only allow HTTPS requests from and to your web server, you'd have to first enable the most restrictive rule, which in this case would be `Nginx HTTPS`, and then disable the currently active `Nginx Full` rule:
```
sudo ufw allow "Nginx HTTPS"
sudo ufw delete allow "Nginx Full"
```
Remember you can list all available application profiles with `sudo ufw app list`.
## Allow SSH
When working with remote servers, you'll want to make sure that the SSH port is open to connections so that you are able to log in to your server remotely.
The following command will enable the OpenSSH UFW application profile and allow all connections to the default SSH port on the server:
```
sudo ufw allow OpenSSH
```
```
Output
Rule added
Rule added (v6)
```
Although less user-friendly, an alternative syntax is to specify the exact port number of the SSH service, which is typically set to `22` by default:
```
sudo ufw allow 22
```
```
Output
Rule added
Rule added (v6)
```
## Allow Incoming SSH from Specific IP Address or Subnet
To allow incoming connections from a specific IP address or subnet, you'll include a `from` directive to define the source of the connection. This will require that you also specify the destination address with a `to` parameter. To lock this rule to SSH only, you'll limit the `proto` (protocol) to `tcp` and then use the `port` parameter and set it to `22`, SSH's default port.
The following command will allow only SSH connections coming from the IP address `203.0.113.103`:
```
sudo ufw allow from 203.0.113.103 proto tcp to any port 22
```
```
Output
Rule added
```
You can also use a subnet address as `from` parameter to allow incoming SSH connections from an entire network:
```
sudo ufw allow from 203.0.113.0/24 proto tcp to any port 22
```
```
Output
Rule added
```
## Allow Incoming Rsync from Specific IP Address or Subnet
The [Rsync](https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories) program, which runs on port `873`, can be used to transfer files from one computer to another.
To allow incoming `rsync` connections from a specific IP address or subnet, use the `from` parameter to specify the source IP address and the `port` parameter to set the destination port `873`. The following command will allow only Rsync connections coming from the IP address `203.0.113.103`:
```
sudo ufw allow from 203.0.113.103 to any port 873
```
```
Output
Rule added
```
To allow the entire `203.0.113.0/24` subnet to be able to `rsync` to your server, run:
```
sudo ufw allow from 203.0.113.0/24 to any port 873
```
```
Output
Rule added
```
## Allow Nginx HTTP / HTTPS
Upon installation, the Nginx web server sets up a few different UFW profiles within the server. Once you have Nginx installed and enabled as a service, run the following command to identify which profiles are available:
```
sudo ufw app list | grep Nginx
```
```
Output
Nginx Full
Nginx HTTP
Nginx HTTPS
```
To enable both HTTP and HTTPS traffic, choose `Nginx Full`. Otherwise, choose either `Nginx HTTP` to allow only HTTP or `Nginx HTTPS` to allow only HTTPS.
The following command will allow both HTTP and HTTPS traffic on the server (ports `80` and `443`):
```
sudo ufw allow "Nginx Full"
```
```
Output
Rule added
Rule added (v6)
```
## Allow Apache HTTP / HTTPS
Upon installation, the Apache web server sets up a few different UFW profiles within the server. Once you have Apache installed and enabled as a service, run the following command to identify which profiles are available:
```
sudo ufw app list | grep Apache
```
```
Output
Apache
Apache Full
Apache Secure
```
To enable both HTTP and HTTPS traffic, choose `Apache Full`. Otherwise, choose either `Apache` for HTTP or `Apache Secure` for HTTPS.
The following command will allow both HTTP and HTTPS traffic on the server (ports `80` and `443`):
```
sudo ufw allow "Nginx Full"
```
```
Output
Rule added
Rule added (v6)
```
## Allow All Incoming HTTP (port `80`)
Web servers, such as Apache and Nginx, typically listen for HTTP requests on port `80`. If your default policy for incoming traffic is set to drop or deny, you'll need to create a UFW rule to allow external access on port `80`. You can use either the port number or the service name (`http`) as a parameter to this command.
To allow all incoming HTTP (port `80`) connections, run:
```
sudo ufw allow http
```
```
Output
Rule added
Rule added (v6)
```
An alternative syntax is to specify the port number of the HTTP service:
```
sudo ufw allow 80
```
```
Output
Rule added
Rule added (v6)
```
### Allow All Incoming HTTPS (port `443`)
HTTPS typically runs on port `443`. If your default policy for incoming traffic is set to drop or deny, you'll need to create a UFW rule to allow external access on port `443`. You can use either the port number or the service name (`https`) as a parameter to this command.
To allow all incoming HTTPS (port `443`) connections, run:
```
sudo ufw allow https
```
```
Output
Rule added
Rule added (v6)
```
An alternative syntax is to specify the port number of the HTTPS service:
```
sudo ufw allow 443
```
```
Output
Rule added
Rule added (v6)
```
## Allow All Incoming HTTP and HTTPS
If you want to allow both HTTP and HTTPS traffic, you can create a single rule that allows both ports. This usage requires that you also define the protocol with the `proto` parameter, which in this case should be set to `tcp`.
To allow all incoming HTTP and HTTPS (ports `80` and `443`) connections, run:
```
sudo ufw allow proto tcp from any to any port 80,443
```
```
Output
Rule added
Rule added (v6)
```
## Allow MySQL Connection from Specific IP Address or Subnet
MySQL listens for client connections on port `3306`. If your MySQL database server is being used by a client on a remote server, you'll need to create a UFW rule to allow that access.
To allow incoming MySQL connections from a specific IP address or subnet, use the `from` parameter to specify the source IP address and the `port` parameter to set the destination port `3306`.
The following command will allow the IP address `203.0.113.103` to connect to the server's MySQL port:
```
sudo ufw allow from 203.0.113.103 to any port 3306
```
```
Output
Rule added
```
To allow the entire `203.0.113.0/24` subnet to be able to connect to your MySQL server, run:
```
sudo ufw allow from 203.0.113.0/24 to any port 3306
```
```
Output
Rule added
```
## Allow PostgreSQL Connection from Specific IP Address or Subnet
PostgreSQL listens for client connections on port `5432`. If your PostgreSQL database server is being used by a client on a remote server, you need to be sure to allow that traffic.
To allow incoming PostgreSQL connections from a specific IP address or subnet, specify the source with the `from` parameter, and set the port to `5432`:
```
sudo ufw allow from 203.0.113.103 to any port 5432
```
```
Output
Rule added
```
To allow the entire `203.0.113.0/24` subnet to be able to connect to your PostgreSQL server, run:
```
sudo ufw allow from 203.0.113.0/24 to any port 5432
```
```
Output
Rule added
```
## Block Outgoing SMTP Mail
Mail servers, such as Sendmail and Postfix, typically use port `25` for SMTP traffic. If your server shouldn't be sending outgoing mail, you may want to block that kind of traffic. To block outgoing SMTP connections, run:
```
sudo ufw deny out 25
```
```
Output
Rule added
Rule added (v6)
```
This configures your firewall to **drop** all outgoing traffic on port `25`. If you need to reject outgoing connections on a different port number, you can repeat this command and replace `25` with the port number you want to block.
## Conclusion
UFW is a powerful tool that can greatly improve the security of your servers when properly configured. This reference guide covers some common UFW rules that are often used to configure a firewall on Ubuntu.
Most of the commands in this guide can be adapted to fit different use cases and scenarios, by changing parameters such as the source IP address and/or destination port. For more detailed information about each command parameter and available modifiers, you can use the `man` utility to check UFW's manual:
```
man ufw
```
The [official UFW page on Ubuntu's documentation](https://help.ubuntu.com/community/UFW) is another resource you can use as reference for more advanced use cases and examples.

123
Linux/WSL.md Normal file
View file

@ -0,0 +1,123 @@
# Run Multiple Instances of the Same Linux Distro on WSL
Step 1.1: Open "Settings"
Step 1.2: Click on "Apps"
Step 1.3: Click on "Installed Apps"
Step 1.4: Select Linux Distro Name --- e.g., Ubuntu 22.04.1 LTS
Step 1.5: Click on the "Advanced Options" link
Step 1.6: Click on the "Reset" button to reset your Linux Distro (e.g., Ubuntu 22.04.1 LTS) to the initial install state. Please note that everything will be deleted.
Step 1.7: When the reset is completed, start your Linux Distro (e.g., Ubuntu 22.04.1 LTS) then set up your Linux Distro by entering both username and password.
Step 1.8: Run "`sudo apt-get update`" (for Ubuntu 22.04.1 LTS) to retrieve information about what packages can be installed, including what updates to currently installed packages are available, from Internet sources.
Step 1.9: Run "`sudo apt-get upgrade`" (for Ubuntu 22.04.1 LTS) to install available upgrades of all packages currently installed on the system from Internet sources.
2\. Export Linux Distro on WSL
_The second step is to create an export image of your Linux Distro. This image will be used to create multiple instances of the same Linux Distro._
Step 2.1: Open a new command prompt or a new Powershell.
Step 2.2: Run the command
```
wsl --list
```
to view a list of Windows Subsystems for Linux Distributions installed on your computer. For example on my computer, it would be "Ubuntu-20.04".
![](https://miro.medium.com/v2/resize:fit:700/1*3j_mQSc4t7tbmXVW26HFlA.png)
Step 2.3: Run the command
```
wsl --export <DistributionName> <FileName>
```
or
```
wsl --export Ubuntu-22.04.1 rootfs.tar.gz
```
to export your Linux distros to a TAR file. This will create a file entitled "rootfs.tar.gz" on your computer. Keep this file safe since you will need this file to create a new instance of the WSL Linux Distro.
![](https://miro.medium.com/v2/resize:fit:700/1*dOwj1uqXukoz4GBVdM_dGg.png)
Step 2.4: Copy the newly created file named "rootfs.tar.gz" to your desired directory. For example on my computer, I have copied the file to c:\linux directory.
3\. Install a New Instance of the Same Linux Distro on WSL
Step 3.1. Open a new command prompt or a new Powershell then run the following command to import exported instance as a new instance of Linux in WSL.
```
wsl --import DistroName InstallationPath ExportedFileLocation
```
for example,
```
wsl --import Ubuntu-22.04.1.02 c:\linux\ubuntu-22.04.1.02 c:\linux\rootfs.tar.gz
```
_I have named DistroName as Ubuntu-22.04.1.02 to specify this is Ubuntu 22.04.1 Instance 2._
For WSL2, the installation process should create "ext4.vhdx" file. Delete copied "rootfs.tar.gz" after the installation is completed.
![](https://miro.medium.com/v2/resize:fit:700/1*UhY0AqYXr8Ue0ujHWS10KA.png)
Step 3.2. Run the newly imported Linux distro.
```
wsl -d DistroName
```
for example
```
wsl -d Ubuntu-22.04.1.02
```
This should start the new instance of Linux Distro in WSL.
![](https://miro.medium.com/v2/resize:fit:700/1*-XtsR5URNKzlUd8yU4SdjA.png)
Step 3.3. Configure new Linux distro by creating "/etc/wsl.conf" file.
then enter the following to wsl.conf file then save the file. This is needed to replicate the default behavior of your default Linux distro instance on WSL where you are logged in as a specified user and mounted to its home directory.
```
[automount]
enabled=true
root=/
[user]
default=sungkim
[interop]
appendWindowsPath = false
[boot]
systemd=true
```
_Please note that you will have to change your username (e.g., sungkim). For more information on wsl.conf, please refer to this website from Microsoft =>_ [_https://learn.microsoft.com/en-us/windows/wsl/wsl-config_](https://learn.microsoft.com/en-us/windows/wsl/wsl-config)_._
Step 3.4. Restart Linux Distro
Exit out of Linux Distro
```
exit
```
then from either the command prompt or PowerShell, enter
```
wsl --shutdown
```
Close Windows Terminal then restart Windows Terminal. A new WSL instance will just show up in Windows Terminal. In Windows Terminal, click on drop-arrow then select the Linux distro name (e.g., Ubuntu-22.04.1.02) to start your new terminal session.