-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33f5582
commit 19d9700
Showing
6 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters