Linux


tar (gz,bz2)

faire une archive

tar -cvzf archivedossier.tar.gz dossieraArchiver

decompresser l'archive

tar -xvzf archivedossier.tar.gz

Attention : pour faire un bz2 remplacer z par j

tar -cvjf archivedossier.tar.bz2 dossierAarchiver
tar (gz,bz2) but exclude some files and directory

tar --exclude='dossier_ou_fichier'-cvjf archivedossier.tar.bz2 dossierAarchiver

Incremental Backups with tar

You can do an incremental backup with tar using the -N (or the equivalent --newer), or the --after-date options. Either option requires specifying either a date or a qualified (reference) file name. See commands below:

$ tar --create --newer '2011-12-1' -vzf backup1.tgz /var/tmp
$ tar --create --after-date '2011-12-1' -vzf backup1.tgz /var/tmp

Either form creates a backup archive of all files in /var/tmp which were modified after December 1, 2011.

Because tar only looks at a file's date, it does not consider any other changes to the file, such as permissions or file name. To include files with these changes in the incremental backup, use find and create a list of files to be backed up.


Type de disque

Linux automatically detects SSD, and since kernel version 2.6.29, you may verify sda with:

cat /sys/block/sda/queue/rotational

You should get 1 for hard disks and 0 for a SSD.

It will probably not work if your disk is a logical device emulated by hardware (like a RAID controller).


resize partition

parted resizepart puis resize2fs ou wfs_growfs ( https://www.thegeekdiary.com/how-to-grow-extend-xfs-filesytem-in-centos-rhel-using-xfs_growfs-command/ )


multiple copie avec nom utilisateur
for i in $(find /home -type f -name id_rsa); do cp $(i) /home/monrepertoire/id_rsa_$(stat -c %U $(i)); done;

ssh-agent error

renvoi des informations sur l'agent ssh

ssh-agent -s

pour forcer la connaissance

eval $(ssh-agent -s)

automatically create all authorized_keys
for i in $(find /home -type f -name "id_rsa.pub" ); do cat ${i} > /home/$(stat -c %U ${i})/authorized_keys; done;

chmod 600 dessus

for i in $(find /home -type f -name authorized_keys) ; do chmod 600 ${i}; done;

chown dessus

for i in $(find /home -type f -name id_rsa) ; do chown $(stat -c %U ${i}):$(stat -c %U ${i}) /home/$(stat -c %U ${i})/authorized_keys ; done;

Automaticaly create txt file with all id_rsa
#!/bin/bash
for i in $(find /home -type f -name "id_rsa")
do 
    echo $(stat -c %U ${i}) >> "$HOME/info.txt"
    cat ${i} >> "$HOME/info.txt"
done


rsa open-ssh instead of rsa

Add option -m PEM into your ssh-keygen command. For example, you can run

ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]"

to force ssh-keygen to export as PEM format.


sed a path
sed -i 's#/path/to/AAA#/path/to/BBB#g' your_file

SSHd config (rsa key only)
vim /etc/ssh/sshd_config

Add

PasswordAuthentication no
PubkeyAuthentication yes

erreur yum

utiliser yum (update - install - ...) provoque l'erreur suivante:

error: db5 error(5) from dbenv->open: Input/output error
error: cannot open Packages index using db5 - Input/output error (5)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

ou un erreur du type

rpmdb: Thread/process 7977/139764163434432 failed: Thread died in Berkeley DB library
error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3  (-30974)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

Error: rpmdb open failed

pour resoudre le probleme effectuer les operations suivantes:

mv /var/lib/rpm/__db* /tmp

yum clean all

yum update

Disk and inode problem

il peut arriver d'avoir de l'espace disque mais de ne pas réussir à lancer des process ou impossible de copier des choses.

Cela provient suovent des inodes. Pour tester utiliser la commande :

df -hi
Quelle dossier contient le plus d'inode occupé
find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n

Astuce copie
cp -R t1/. t2/

Le point à la fin indique qu'il faut copier le contenu du répertoire courant, et non le répertoire lui-même. Cette méthode inclut également les fichiers et dossiers cachés.


Erreur : Échec du téléchargement des métadonnées pour le dépôt « appstream » : Cannot prepare internal mirrorlist: No URLs in mirrorlist

CentOS Linux 7 EOL: 2024-06-30

CentOS Linux 8 EOL: 2021-12-31

CentOS Stream 8 EOL: 2024-05-31

CentOS Stream 9 EOL: estimated 2027, dependent on RHEL9 end of “Full Support Phase”

If you dont already have it, you'll need the gpg keys

wget 'http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-3.el8.noarch.rpm'
sudo rpm -i 'centos-gpg-keys-8-3.el8.noarch.rpm'

Then it's as simple as transitioning like so

dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos

Don't worry it doesnt remove any repos, it simply temporarily ignores all of yours, and downloads information regarding the new mirrors.

You may at this point want to actually upgrade your packages

sudo dnf distro-sync

You'll now be able to use "yum" as usual.

SCP

From local to remote

scp file.txt [email protected]:/remote/directory
Fail2ban

Unban ip

Use iptables to find the rule

iptables -L -n

Sometimes it's not true, check the conf in /etc then unban

fail2ban-client set YOURJAILNAMEHERE unbanip IPADDRESSHERE
Send mail
echo "Message Body Here" | mail -s "Subject Here" [email protected] -A backup.zip

==> https://www.tecmint.com/send-email-attachment-from-linux-commandline/

Know your public ip
dig +short myip.opendns.com @resolver1.opendns.com
List all user cron job
for user in $(cut -f1 -d: /etc/passwd); do echo $user ; crontab -u $user -l 2>/dev/null | grep -v '^#'; done
yumRepoError Centos 6

Suite à la tentative d'installation d'un package sur une vieille distribution centos 6 j'ai le message d'erreur suivant :

Loaded plugins: fastestmirror, presto, security
Setting up Install Process
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
cause

La cause de cette erreur est que CentOS 6 est en fin de vie (30 novembre 2020) et que les dépôts sont dépréciés.

Resolution

La résolution du problème consiste à supprimer l'ancien miroir et le lien baseurl pour les dépôts CentOS et à le remplacer par le lien CentOS vault.

Avant toute opérations faire un backup de son dépot

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-old

Ensuite nous allons créer un nouveau dépot

vim /etc/yum.repos.d/CentOS-Base.repo

Et mettre les dépots suivants

[base]
name=CentOS-$releasever - Base
baseurl=https://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://vault.centos.org/6.10/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[extras]
name=CentOS-$releasever - Extras
baseurl=https://vault.centos.org/6.10/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Maintenant nous allons faire un clean des dépot et un refresh des depot

yum clean all
yum repolist

Et voila ^_^