Skip to content

Commit

Permalink
general update
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmarceleza committed Dec 30, 2021
1 parent 33f5582 commit 19d9700
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 0 deletions.
55 changes: 55 additions & 0 deletions databases/mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
MySQL
========================

## Comandos básicos

Comando para listar todos os bancos e sua utilização de disco:

```
SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
```

## Backup do banco de dados

### Comando básico para gerar o backup de um banco de dados:

```bash
$ mysqldump -u [USER] -p [NOME_DO_BANCO] > backup.sql
```

Se usar o parâmetro `--databases`, não será necessário criar um banco vazio antes de fazer a importação.

### Comando para restaurar o backup do banco de dados:

- Antes de restaurar o backup, é importante criar o banco de dados vazio para receber as informações, caso não se tenha utilizado o parâmetro `--databases`.

```bash
$ mysqladmin create [DB_VAZIO]
```

```bash
$ mysql -u [USER] -p [DB_VAZIO] < backup.sql
```

- Caso se tenha usado a opção `--databases`, a sintaxe fica da seguinte forma:

```bash
$ mysql -u [USER] -p < backup.sql
```

### Backup via Crontab:

Para automatizar o processo de backup, é mais fácil criar um script com as instruções e cadastrar no Crontab para executar regularmente. Ao utilizar o MySQL no Shell, a senha de usuário do banco de dados é requerida. Para não pausar o processo na etapa de solicitação dessa senha, recomenda-se fazer o seguinte procedimento:

- criar o arquivo oculto `.my.cnf` na pasta `/root/`;
- mudar as permissões para apenas o root ter acesso `# chmod 600 .my.cnf`
- colocar as informações de acesso no arquivo conforme abaixo:

```bash
[client]
user=root
password="ROOT_PASSWORD"
```
12 changes: 12 additions & 0 deletions kubernetes/jsonpath/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ List Taints of all nodes:
```
kubectl get nodes -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.taints}{"\n"}{end}'
```

List images of all pods:

```
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
```

List roleRef of all clusterrolebinding:

```
oc get clusterrolebinding -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.roleRef.name}{"\n"}{end}'
```
48 changes: 48 additions & 0 deletions linux/powerline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Powerline
This is a simple guide to install `Powerline` to make your terminal look beautiful

Useful links:
* [Powerline GitHub](https://github.com/powerline/powerline)
* [Powerline Documentation](https://powerline.readthedocs.io/en/latest/)

## Instalation

### Manjaro
```bash
$ sudo pacman -S powerline
```
### Ubuntu
```bash
$ sudo apt install powerline
```
## Configure Bash
To configure Powerline for bash, add the following lines to your `$HOME/.bashrc` file:
```bash
# Powerline configuration
if [ -f /usr/share/powerline/bindings/bash/powerline.sh ]; then
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source /usr/share/powerline/bindings/bash/powerline.sh
fi
```
To apply the changes to your current terminal:
```bash
$ source ~/.bashrc
```
After running the previous command or restarting your terminal, the Powerline segments appear in your prompt.
## Configure Vim
To configure Powerline for Vim, add the following lines to your `$HOME/.vimrc` file:
```bash
python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup

set laststatus=2
```
## Configure tmux
To configure Powerline in tmux, add the following to your `~/.tmux.conf` file:
```bash
set -g default-terminal "screen-256color"
source "/usr/share/powerline/bindings/tmux/powerline.conf"
```
62 changes: 62 additions & 0 deletions linux/ssh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# SSH
SSH is a network protocol to secure connections between devices, like clients and servers. Because SSH transmits data over encrypted channels, security is at a high level.
## Prerequisites
Considering a connection with a client and a server, here are the prerequisites:
- An SSH client of your choice
- An SSH server on the remote machine
- The IP address or name of the remote server
## How to Access a Remote Server
To connect to a remote machine, you need its IP address or name and a user. Load the terminal or any SSH client and type ssh command like the following syntax :
```bash
ssh username@hostname_or_ip
```
By default, the port to access the remote machine is 22. It's possible to change the port by accessing the configuration file on the remote. To connect to a remote host with a custom SSH port number, use the -p flag. For example:
```bash
ssh username@hostname_or_ip -p 6969
```
## Improving security with SSH Keys
To avoid brutal force attacks is recommended to disable the password login method and use a pair of ssh keys, one public to put on the server and another private on the client side.
### Create the SSH Keys
The first step is to create the key pair on the client machine:
```bash
$ ssh-keygen
```
You will receive some questions about the place to save the keys and a passphrase to encrypt it. Let them in the suggested place `/home/user/.ssh/` and choose a great passphrase to guarantee the security.
### Copy the Public Key to the Remote Machine
There's an easy command to simplify this process
```bash
$ ssh-copy-id username@hostname_or_ip
```
Alternatively, you can paste in the keys using SSH:
```bash
$ cat ~/.ssh/id_rsa.pub | ssh username@hostname_or_ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
```
### Disable the Password for Root Login
Once you copied the public key to the server, ensured you can log in with those keys. After check that everything is fine, disable the password for root login to increase security. In order to do this, open up the SSH configuration file:
```bash
$ sudo vim /etc/ssh/sshd_config
```
Find the line with `PermitRootLogin` and uncommented it modifying like this: `PermitRootLogin no`

[10 Actionable SSH Hardening Tips to Secure Your Linux Server](https://linuxhandbook.com/ssh-hardening-tips/)

PermitRootLogin
PasswordAuthentication
PubkeyAuthentication
## SSH LAB
CLIENT
192.168.33.10

SERVER
192.168.33.11
user: root
password: root

user: normal_user
password: normal_user

user: super_user
password: super_user



29 changes: 29 additions & 0 deletions openshift/authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,33 @@ Delete the Identity object for the user:

```
oc delete identity my_htpasswd_provider:<username>
```

## Role Binding/Cluster Role Binding

- Local role binding operations:

| Command | Description |
| --- | --- |
| oc adm policy who-can <verb> <resource> | Indicates which users can perform an action on a resource. |
| oc adm policy add-role-to-user <role> <username> | Binds a specified role to specified users in the current project. |
| oc adm policy remove-role-from-user <role> <username> | Removes a given role from specified users in the current project. |
| oc adm policy remove-user <username> | Removes specified users and all of their roles in the current project. |
| oc adm policy add-role-to-group <role> <groupname> | Binds a given role to specified groups in the current project. |
| oc adm policy remove-role-from-group <role> <groupname> | Removes a given role from specified groups in the current project. |
| oc adm policy remove-group <groupname> | Removes specified groups and all of their roles in the current project. |

- Cluster role binding operations

| Command | Description |
| --- | --- |
| oc adm policy add-cluster-role-to-user <role> <username> | Binds a given role to specified users for all projects in the cluster. |
| oc adm policy remove-cluster-role-from-user <role> <username> | Removes a given role from specified users for all projects in the cluster. |
| oc adm policy add-cluster-role-to-group <role> <groupname> | Binds a given role to specified groups for all projects in the cluster. |
| oc adm policy remove-cluster-role-from-group <role> <groupname> | Removes a given role from specified groups for all projects in the cluster. |

- Define the user as a cluster admin:

```
oc adm policy add-cluster-role-to-user cluster-admin <user>
```
53 changes: 53 additions & 0 deletions vagrant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,59 @@
$ sudo pacman -S vagrant
```

## Basic commands
First, It is necessary to create a directory for you virtual machine (VM), where a configuration file (`Vagrantfile`) will be saved to manage the configurations.
```bash
$ mkdir [VM FOLDER NAME]
```
Move into your directory:
```bash
$ cd [VM FOLDER NAME]
```
Command to initialize and create a Vagrantfile to a specific VM, also called as BOX in the Vagrant terminology.
```bash
$ vagrant init [BOX NAME]
```
To find the correct name for boxes, search [Vagrant Cloud](https://app.vagrantup.com/boxes/search) for a complete list.

Optionally, you can download a box without creating a Vagrantfile. With the previous command the base image of the box is not download by default. This will happen only when you give the command to run or start the VM (`vagrant up`). If you to download to increase your library of boxes, simply use the following command:
```bash
$ vagrant box add [BOX NAME]
```
Command to run a VM:
```bash
$ vagrant up
```
You can check if the machine is running with this:
```bash
$ vagrant status
```
To access the VM, use ssh:
```bash
$ vagrant ssh
```
To stop the VM, use this:
```bash
$ vagrant halt
```
To destroy the machine:
```bash
$ vagrant destroy
```
This last command do not remove the box, only the VM. In this case, if you want to remove the box, use the following command:
```bash
$ vagrant box remove [BOX NAME]
```
To configure port forwarding you need to modify the Vagrantfile with this line:
```bash
config.vm.network :forwarded_port, guest: 80, host: 4567
```
Reload the VM to take effect.
```bash
$ vagrant reload
```
Once the machine is running again, load `http://127.0.0.1:4567` in your browser, where you will access your application.

## Documentation

- [Vangrant Documentation](https://www.vagrantup.com/docs)
Expand Down

0 comments on commit 19d9700

Please sign in to comment.