TOC and ssh revision

This commit is contained in:
2024-06-08 05:53:28 +01:00
parent 04f5e208c4
commit c1686b9d25

215
README.md
View File

@@ -1,34 +1,92 @@
<!-- TOC -->
- [hostname/hostnamectl](#hostnamehostnamectl)
- [Update](#update)
- [Debian / Ubuntu](#debian--ubuntu)
- [Fedora](#fedora)
- [ls](#ls)
- [Users](#users)
- [hostame](#hostame)
- [static ip](#static-ip)
- [Disks](#disks)
- [mount](#mount)
- [gio](#gio)
- [mount samba share](#mount-samba-share)
- [unmount](#unmount)
- [File System](#file-system)
- [ext4](#ext4)
- [ext3](#ext3)
- [exFat](#exfat)
- [ntfs](#ntfs)
- [space usage](#space-usage)
- [Manutenção de discos](#manutenção-de-discos)
- [tar](#tar)
- [SSH](#ssh)
- [Create key](#create-key)
- [Copy public key](#copy-public-key)
- [Add existing Key](#add-existing-key)
- [alias](#alias)
- [Benchmarking](#benchmarking)
- [themes](#themes)
- [shell](#shell)
- [terminal](#terminal)
- [Backups](#backups)
- [bash](#bash)
- [disable touh screen](#disable-touh-screen)
- [disable suspend blackscreen](#disable-suspend-blackscreen)
- [lightdm auto login](#lightdm-auto-login)
- [btop](#btop)
- [Setup](#setup)
- [Debian & Ubuntu](#debian--ubuntu)
- [lspci](#lspci)
- [gnome files / nautilus](#gnome-files--nautilus)
<!-- /TOC -->
# Linux
## Comands
## hostname/hostnamectl
```bash
# OS information
hostnamectl
#get hostname
hostname
#system update
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
#set hostname
hostnamectl
```
## Update
### Debian / Ubuntu
```bash
apt update -y
apt upgrade -y
apt autoremove -y
```
References:
[https://linuxsimply.com/linux-basics/package-management/update-packages/sudo-apt-update/](https://linuxsimply.com/linux-basics/package-management/update-packages/sudo-apt-update/)
### Fedora
```bash
dnf
```
References:
[https://docs.fedoraproject.org/en-US/quick-docs/dnf-vs-apt/](https://docs.fedoraproject.org/en-US/quick-docs/dnf-vs-apt/)
## ls
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
List information about the FILEs (the current directory by default).
```bash
#order by date
ls -t
```bash
#order by date
ls -t
#order by date reverse
ls -r
```
```
source: man
@@ -56,7 +114,9 @@ chown [-c|--changes] [-v|--verbose] [-f|--silent|--quiet] [--dereference]
[-R|--recursive] [--preserve-root] [-H] [-L] [-P]
{new-owner|--reference=ref-file} file ...
```
## hostame
```
sudo nano /etc/hostname
#alterar o nome
@@ -69,8 +129,9 @@ A configuração para um ip estático poderá ser um pouco diferente de distribu
## static ip
Debian
sudo nano /etc/network/interfaces
sudo nano /etc/network/interfaces
Exemplo de configuração
```
# neste exemplo de configuração a place de rede tem o nome enxd0374555c1f8
@@ -93,6 +154,7 @@ iface enxd0374555c1f8 inet static
dns-nameservers 89.207.128.252 89.207.130.252
Reiniciar configuração sem reboot de computador
```
```
Reiniciar configuração sem reboot de computador
#sudo /etc/init.d/networking restart
@@ -118,8 +180,8 @@ List partition ids
blkid /dev/sdc1
```
Partition Manager
```
fdisk /dev/<DISK NAME>
#Example:
@@ -136,21 +198,22 @@ sudo parted /dev/sdc
mkpart primary ext4 0 4
#Formatar uma partição
```
## mount
## mount
Mount partion on boot fstab
```
nano /etc/fstab
nano /etc/fstabexemplo de alias
```
ext4 example
```
#add line
PARTUUID=<PARTUUID GIVEN blksid> <FOLDER WHERE TO MOUNT> ext4 defaults,nofail 0 02
```
Mount fstab partions without reboot
```
@@ -184,6 +247,7 @@ Add line
## gio
### mount samba share
```bash
#/home/username/.credentials
#username
@@ -198,7 +262,6 @@ gio mount smb://server/share < /home/username/.credentials
gio mount -u smb://server/share
```
## File System
### ext4
@@ -206,6 +269,7 @@ gio mount -u smb://server/share
mkfs.ext4 _filesys_
Example
```
mkfs.ext4 /dev/sdb1
```
@@ -215,6 +279,7 @@ mkfs.ext4 /dev/sdb1
mkfs.ext3 _filesys_
Example
```
mkfs.ext3 /dev/sdb1
#exFat
@@ -225,6 +290,7 @@ mkfs.exfat /dev/sdc1
### exFat
mkfs.exfat _filesys_
```
mkfs.exfat /dev/sdc1
```
@@ -238,16 +304,16 @@ mkntfs --fast --label Backups /dev/sdc1
## space usage
df
df
df -h
df -h
du -h --max-depth=1
du -h --max-depth=1
## Manutenção de discos
Bad Sectors
sudo e2fsck -cfpv /dev/sda1
sudo e2fsck -cfpv /dev/sda1
O Exemplo foi com o disco sda1 mas deverá ser subsituido pelo disco desejado
Os parâmetros têm os seguintes significados:
@@ -265,6 +331,7 @@ Esse comando pode levar muito tempo para ser executado, até várias horas em um
## tar
A utilização o comando tar é uma das formas de comprimir no linux
```
tar -cvf --exclude='.cache' --exclude='Cache' --exclude='.cache' --exclude='.tmp' --exclude='tmp' /tmp/nomedoficheiro.tar.gz /PATHPARAFICEHIROOUDIRECTORIO
@@ -273,61 +340,57 @@ tar -I pigz -cvf - /fileserver/media/music/*
#Se for necessário limitar o tamanho do ficheiro compresso (dividindo em multiplos ficheiros)
tar -I pigz -cvf - /sourcefolder/* | split --bytes=8GB - /tmp/file.tar.gz
```
```
## SSH
para executar comandos por ssh que usem o display do servidor, começar por executar:
export DISPLAY=:0
screen
Para mais informações como manter o comando a executar mesmo que termine a sessão de ssh consultar:Screen
### Create key
sem password
criar chaves (publica e privada) no cliente
```
```bash
ssh-keygen -t ecdsa -b 521
Se for necessário controlar o nome do ficheiro
#or
ssh-keygen -t ecdsa -b 521 -f ~/.ssh/key-ecdsa
#substituir ~/.ssh/id_ecdsa/mf-key-ecdsa com o path de destino e o nome pretendido
# o directório tem que existir, por isso se não existir:
# mkdir ~/ssh/id_ecdsa
ssh-keygen -t ecdsa -b 521 -f ~/.ssh/mf-key-ecdsa
copiar a chave para o servidor
ssh-copy-id -i ~/.ssh//mf-key-ecdsa.pub example_user@192.0.2.4
testar o ssh para ver se funcionou (ou seja não pede a password)
ssh example_user@192.0.2.4
se pedir a password e indicar algo semelhante a It is required that your private key files are NOT accessible by others. será necessario rever as permissões do ficheiro indicado na informação Exemplo:
chmod g-rwx,o-rwx ~/.ssh/mf-key-ecdsa
Para adicionar o chave existente no ssh-agent (só necessario se a chave privada for copiada de outro sitio)
```
eval `ssh-agent`
ssh-add pathenomedoficheiro
### Copy public key
Caso o servidor de SSH seja em windows e necessario alterara segraunça do authorized_keys
```bashssh-add ~/.ssh/id_ed25519
ssh-copy-id -i ~/.ssh//ey-ecdsa.pub example_user@192.0.2.4
```
get-acl c:\ProgramData\ssh\ssh_host_dsa_key | set-acl C:\Users\[username]\.ssh\authorized_keys
### Add existing Key
```bash
ssh-add ~/.ssh/key-ecdsa
```
### alias
```bash
Host srv01
HostName srv01.lan
User john
RemoteCommand cd ~/; exec bash --login
RequestTTY yes
```
## Benchmarking
Discos
sudo apt install hdparm
sudo hdparm -Tt /dev/sdc
## themes
- https://github.com/EliverLara/Nordic
### shell
- https://github.com/EliverLara/Nordic
### shell
- zsh
``` bash
```bash
sudo apt install zsh
chsh -s /bin/zsh $whoami
sudo apt-get install fonts-powerline
@@ -339,18 +402,17 @@ ssh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/ma
#ZSH_THEME="agnoster"
```
### terminal
- guake
- guake
``` bash
```bash
apt install guake
```
``` bash
```
```bash
# ~/.config/autostart/guake.desktop
[Desktop Entry]
[Desktop Entry]
Name=guake
GenericName=guake auto start
Comment=
@@ -362,14 +424,15 @@ X-GNOME-Autostart-enabled=true
- terminator
``` bash
```bash
apt install terminator
```
```
## Backups
``` bash
### bash
```bash
tar -cvpzf "/vault/.backups/devices/homeserver/tar/backup_$(date +"%Y%m%d%H%M%S").tar.gz \
--exclude=/proc \
--exclude=/tmp \
@@ -382,7 +445,7 @@ tar -cvpzf "/vault/.backups/devices/homeserver/tar/backup_$(date +"%Y%m%d%H%M%S"
/
```
``` bash
```bash
#!/bin/bash
gio mount ftp://ftp.backups@backupsrv01.dev.lan < ~/.credentials/ftp.backups@backupsrv01.dev.lan
@@ -400,7 +463,8 @@ gio mount -u ftp://ftp.backups@backupsrv01.dev.lan
```
## disable touh screen
```
``` bash
sudo apt-get -y install xinput
xinput
```
@@ -421,7 +485,6 @@ Source: https://askubuntu.com/questions/759335/how-to-disable-a-touchscreen-on-s
[Seat:*]
xserver-command=X -s 0 dpms
```
## lightdm auto login
```bash
@@ -433,13 +496,12 @@ autologin-user-timeout=5
#greeter-session=unity-greeter
```
## btop
### Setup
#### Debian & Ubuntu
```bash
apt update && apt install btop -y
```
@@ -450,10 +512,13 @@ Displays information about each PCI bus on your system. This includes informatio
lspci [options]
| Option |Description |
|--------|----------------------------------------------------|
| -v | Verbose |
```
| Option | Description |
| -------- | ------------- |
| -v | Verbose |
``` bash
lspci -v
```