add gitea config and ssh note

This commit is contained in:
mohamad24xx 2022-08-05 18:31:06 +04:30
parent ae52761d5e
commit f3a0bdd5fb
6 changed files with 204 additions and 17 deletions

View file

@ -12,5 +12,6 @@
"promptDelete": true, "promptDelete": true,
"trashOption": "local", "trashOption": "local",
"readableLineLength": true, "readableLineLength": true,
"alwaysUpdateLinks": true "alwaysUpdateLinks": true,
"tabSize": 4
} }

View file

@ -1,5 +1,5 @@
{ {
"baseFontSize": 21, "baseFontSize": 20,
"translucency": false, "translucency": false,
"enabledCssSnippets": [ "enabledCssSnippets": [
"obsidian" "obsidian"

View file

@ -4,12 +4,12 @@
"type": "split", "type": "split",
"children": [ "children": [
{ {
"id": "2a83dd53ceb96ad7", "id": "b9b7d20fec712772",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "markdown", "type": "markdown",
"state": { "state": {
"file": "Programing/Html & Css/Recipes/button.md", "file": "Programing/Vim/plugins keybinding.md",
"mode": "source", "mode": "source",
"source": false "source": false
} }
@ -77,7 +77,7 @@
"state": { "state": {
"type": "backlink", "type": "backlink",
"state": { "state": {
"file": "Programing/Html & Css/Recipes/button.md", "file": "Programing/Vim/plugins keybinding.md",
"collapseAll": false, "collapseAll": false,
"extraContext": false, "extraContext": false,
"sortOrder": "alphabetical", "sortOrder": "alphabetical",
@ -94,7 +94,7 @@
"state": { "state": {
"type": "outgoing-link", "type": "outgoing-link",
"state": { "state": {
"file": "Programing/Html & Css/Recipes/button.md", "file": "Programing/Vim/plugins keybinding.md",
"linksCollapsed": false, "linksCollapsed": false,
"unlinkedCollapsed": true "unlinkedCollapsed": true
} }
@ -117,7 +117,7 @@
"state": { "state": {
"type": "outline", "type": "outline",
"state": { "state": {
"file": "Programing/Html & Css/Recipes/button.md" "file": "Programing/Vim/plugins keybinding.md"
} }
} }
}, },
@ -137,17 +137,17 @@
"width": 300, "width": 300,
"collapsed": true "collapsed": true
}, },
"active": "2a83dd53ceb96ad7", "active": "b9b7d20fec712772",
"lastOpenFiles": [ "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", "cheat sheats/Format your notes.md",
"Programing/Vim/plugins keybinding.md", "Programing/Vim/plugins keybinding.md",
"Programing/Vim/vim keybinding.md", "Programing/Vim/vim keybinding.md",
"Programing/Vim/plugin list.md",
"Programing/Html & Css/Recipes/button.md",
"Programing/media files/button3.png", "Programing/media files/button3.png",
"Unorganized notes/whater frier.md", "Unorganized notes/whater frier.md",
"Programing/media files/button 1.png", "Programing/media files/button 1.png"
"Unorganized notes/example note.md",
"Programing/Html & Css/Recources/Icones.md"
] ]
} }

View file

@ -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: 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 ### 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: 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. 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) ![activefinal|500](https://www.freecodecamp.org/news/content/images/2022/02/activefinal.gif)

View file

@ -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

View file

@ -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 <username>
```
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 <Gitea Host Key>
# 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 <user pubkey>
```
#### 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
```