From f3a0bdd5fb8de72beda17faf9483c469c2f5a8c6 Mon Sep 17 00:00:00 2001 From: mohamad24xx Date: Fri, 5 Aug 2022 18:31:06 +0430 Subject: [PATCH] add gitea config and ssh note --- Phoenix/.obsidian/app.json | 3 +- Phoenix/.obsidian/appearance.json | 2 +- Phoenix/.obsidian/workspace | 22 +-- .../Programing/Html & Css/Recipes/button.md | 8 +- Phoenix/Programing/Linux commands/ssh.md | 47 ++++++ Phoenix/Programing/Server/gitea setup.md | 139 ++++++++++++++++++ 6 files changed, 204 insertions(+), 17 deletions(-) create mode 100644 Phoenix/Programing/Linux commands/ssh.md create mode 100644 Phoenix/Programing/Server/gitea setup.md diff --git a/Phoenix/.obsidian/app.json b/Phoenix/.obsidian/app.json index fe01f87..879d482 100644 --- a/Phoenix/.obsidian/app.json +++ b/Phoenix/.obsidian/app.json @@ -12,5 +12,6 @@ "promptDelete": true, "trashOption": "local", "readableLineLength": true, - "alwaysUpdateLinks": true + "alwaysUpdateLinks": true, + "tabSize": 4 } \ No newline at end of file diff --git a/Phoenix/.obsidian/appearance.json b/Phoenix/.obsidian/appearance.json index c96d407..d4b00a4 100644 --- a/Phoenix/.obsidian/appearance.json +++ b/Phoenix/.obsidian/appearance.json @@ -1,5 +1,5 @@ { - "baseFontSize": 21, + "baseFontSize": 20, "translucency": false, "enabledCssSnippets": [ "obsidian" diff --git a/Phoenix/.obsidian/workspace b/Phoenix/.obsidian/workspace index 87bcd36..746eaf2 100644 --- a/Phoenix/.obsidian/workspace +++ b/Phoenix/.obsidian/workspace @@ -4,12 +4,12 @@ "type": "split", "children": [ { - "id": "2a83dd53ceb96ad7", + "id": "b9b7d20fec712772", "type": "leaf", "state": { "type": "markdown", "state": { - "file": "Programing/Html & Css/Recipes/button.md", + "file": "Programing/Vim/plugins keybinding.md", "mode": "source", "source": false } @@ -77,7 +77,7 @@ "state": { "type": "backlink", "state": { - "file": "Programing/Html & Css/Recipes/button.md", + "file": "Programing/Vim/plugins keybinding.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -94,7 +94,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Programing/Html & Css/Recipes/button.md", + "file": "Programing/Vim/plugins keybinding.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -117,7 +117,7 @@ "state": { "type": "outline", "state": { - "file": "Programing/Html & Css/Recipes/button.md" + "file": "Programing/Vim/plugins keybinding.md" } } }, @@ -137,17 +137,17 @@ "width": 300, "collapsed": true }, - "active": "2a83dd53ceb96ad7", + "active": "b9b7d20fec712772", "lastOpenFiles": [ + "Programing/Vim/plugin list.md", + "Programing/Server/gitea setup.md", + "Programing/Linux commands/ssh.md", + "Programing/Html & Css/Recipes/button.md", "cheat sheats/Format your notes.md", "Programing/Vim/plugins keybinding.md", "Programing/Vim/vim keybinding.md", - "Programing/Vim/plugin list.md", - "Programing/Html & Css/Recipes/button.md", "Programing/media files/button3.png", "Unorganized notes/whater frier.md", - "Programing/media files/button 1.png", - "Unorganized notes/example note.md", - "Programing/Html & Css/Recources/Icones.md" + "Programing/media files/button 1.png" ] } \ No newline at end of file diff --git a/Phoenix/Programing/Html & Css/Recipes/button.md b/Phoenix/Programing/Html & Css/Recipes/button.md index cce510b..f446f12 100644 --- a/Phoenix/Programing/Html & Css/Recipes/button.md +++ b/Phoenix/Programing/Html & Css/Recipes/button.md @@ -166,7 +166,7 @@ Following that, you can maintain the `outline-style` to `solid`. Lastly, usin } ``` -![focusend](https://www.freecodecamp.org/news/content/images/2022/02/focusend.gif) +![focusend|500](https://www.freecodecamp.org/news/content/images/2022/02/focusend.gif) You can also again pair these styles with the `transition` property, depending on the effect you want to achieve: @@ -179,7 +179,7 @@ You can also again pair these styles with the `transition` property, depending } ``` -![focusend1](https://www.freecodecamp.org/news/content/images/2022/02/focusend1.gif) +![focusend1|500](https://www.freecodecamp.org/news/content/images/2022/02/focusend1.gif) ### How to Style for the `:active` State @@ -187,7 +187,7 @@ The `:active` state gets _activated_ when you click on the button by either That being said, look at what happens when I click the button after I've applied and kept the styles for the `:hover` and `:focus` states: -![active-1](https://www.freecodecamp.org/news/content/images/2022/02/active-1.gif) +![active-1|500](https://www.freecodecamp.org/news/content/images/2022/02/active-1.gif) The `:hover` state styles are applied before clicking when I hover over the button. @@ -207,4 +207,4 @@ In this case, I've changed the background color of the button when a user clicks } ``` -![activefinal](https://www.freecodecamp.org/news/content/images/2022/02/activefinal.gif) \ No newline at end of file +![activefinal|500](https://www.freecodecamp.org/news/content/images/2022/02/activefinal.gif) \ No newline at end of file diff --git a/Phoenix/Programing/Linux commands/ssh.md b/Phoenix/Programing/Linux commands/ssh.md new file mode 100644 index 0000000..bb33457 --- /dev/null +++ b/Phoenix/Programing/Linux commands/ssh.md @@ -0,0 +1,47 @@ +# ssh +### Locating ssh keys +```bash +ls ~/.ssh/id* +``` + +### Generating ssh key pair with rsa +The algorithm is selected using the `-t` option and key size using the `-b` option +```bash +ssh-keygen -t rsa -b 4096 +``` +##### other algorithms are +- `rsa` - an old algorithm based on the difficulty of factoring large numbers. A key size of at least 2048 bits is recommended for RSA; 4096 bits is better. RSA is getting old and significant advances are being made in factoring. Choosing a different algorithm may be advisable. It is quite possible the RSA algorithm will become practically breakable in the foreseeable future. All SSH clients support this algorithm. +- `dsa` - an old US government Digital Signature Algorithm. It is based on the difficulty of computing discrete logarithms. A key size of 1024 would normally be used with it. DSA in its original form is no longer recommended. +- `ecdsa` - a new Digital Signature Algorithm standarized by the US government, using elliptic curves. This is probably a good algorithm for current applications. Only three key sizes are supported: 256, 384, and 521 (sic!) bits. We would recommend always using it with 521 bits, since the keys are still small and probably more secure than the smaller keys (even though they should be safe as well). Most SSH clients now support this algorithm. +- `ed25519` - this is a new algorithm added in OpenSSH. Support for it in clients is not yet universal. Thus its use in general purpose applications may not yet be advisable. + +### Add ssh public key to server +```bash +ssh-copy-id user@remote-host +``` +##### add specific key to remote +``` bash +ssh-copy-id -i ~/.ssh/tatu-key-ecdsa user@remote-host +``` +### Looking up correct ssh folder file permissions +```bash +stat -c "%a %n" ~/.ssh +stat -c "%a %n" ~/.ssh/* +``` +### Fixing the file permissions for .ssh folder +```bash +sudo chown -R $USER:$USER ~/.ssh +sudo chmod 700 ~/.ssh +sudo chmod 600 ~/.ssh/authorized_keys +sudo chmod 400 ~/.ssh/id_rsa +sudo chmod 644 ~/.ssh/id_rsa.pub +sudo chmod 600 ~/.ssh/known_hosts +``` +### Prevent `broken pipe` error +make config file in ~/.shh or and add this +```config +Host * +ServerAliveInterval 120 +``` +or you can set either `ServerAliveInterval` in /etc/ssh/ssh_config of the client machine +or `ClientAliveInterval` in /etc/ssh/ssh_config of the server machine diff --git a/Phoenix/Programing/Server/gitea setup.md b/Phoenix/Programing/Server/gitea setup.md new file mode 100644 index 0000000..43f2a18 --- /dev/null +++ b/Phoenix/Programing/Server/gitea setup.md @@ -0,0 +1,139 @@ +## Gitea docker setup with ssh +#### Check if Git is installed +Check that Git is installed on the server. If it is not, install it first. Gitea requires Git version >= 2.0. +```bash +git --version +``` +#### Create a user to run Gitea +```shell +adduser \ + --system \ + --shell /bin/bash \ + --gecos 'Git Version Control' \ + --group \ + --disabled-password \ + --home /home/git \ + git +``` +#### Change pass word for git user +```shell +passwd username +``` +#### Make user git sudoers +```shell +sudo usermod -aG wheel test-user +``` +#### Find UID +```bash +id -u +``` +or for current user +```bash + echo $UID +``` +change uid and gid in next step for user git +#### make folder for gitea and cd in it +```shell +mkdir gitea +cd gitea +touch docker-compose.yml +``` +#### docker compose yml config +use any editor to change docker-compose.yml with config +```yml +version: "3" + +networks: + gitea: + external: false + +services: + server: + image: gitea/gitea:1.16.9 + container_name: gitea + environment: + - USER_UID=112 #change uid with one from last step + - USER_GID=112 #change gid with one from last step + - GITEA__database__DB_TYPE=postgres + - GITEA__database__HOST=db:5432 + - GITEA__database__NAME=gitea + - GITEA__database__USER=gitea + - GITEA__database__PASSWD=gitea + restart: always + networks: + - gitea + volumes: + - ./gitea:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + - /home/git/.ssh/:/data/git/.ssh # add this for ssh support + ports: + - "3000:3000" + - "127.0.0.1:2222:22" #ssh port to 2222 for gitea + depends_on: + - db + + db: + image: postgres:14 + restart: always + environment: + - POSTGRES_USER=gitea + - POSTGRES_PASSWORD=gitea + - POSTGRES_DB=gitea + networks: + - gitea + volumes: + - ./postgres:/var/lib/postgresql/data +``` +#### seting up and down with docker compose +```bash +docker compose up -d +docker compose down +``` + +#### Give permission to user its home dir +this command is needed when cant use ssh-keygen for another user but root +```bash +chown -R git: /home/git/ +``` +#### Login as git user +```shell +su - username +``` +#### Make ssh key pair +```bash +sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key" +``` +#### set right permission for ssh authorized_keys +```bash +sudo -u git cat /home/git/.ssh/id_rsa.pub | sudo -u git tee -a /home/git/.ssh/authorized_keys +sudo -u git chmod 600 /home/git/.ssh/authorized_keys +``` +Important: The pubkey from the `git` user needs to be added “as is” while all other pubkeys added via the Gitea web interface will be prefixed with `command="/usr [...]`. + +`/home/git/.ssh/authorized_keys` should then look somewhat like +```bash +# SSH pubkey from git user +ssh-rsa + +# other keys from users most likely there is none +command="/usr/local/bin/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty +``` + +#### Exit from git user and run needed command +first exit from user git +```shell +exit +``` +and then run +```bash +cat <<"EOF" | sudo tee /usr/local/bin/gitea +#!/bin/sh +ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@" +EOF +sudo chmod +x /usr/local/bin/gitea +``` +#### remove git user from sudo +```shell +sudo deluser username sudo +```