====== Small tricks ======
{{howhard>1}}
===== Accept a changed ssh key: =====
when you try to log via SSH to a machine that has changed the key, you get something like that
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
..........
In order to reset the saved identification of the machine, run:
ssh-keygen -R
Now you can log again via SSH.
===== connect to CUPS from web interface =====
[[http://localhost:631/|http://localhost:631/]]
===== Copy / synchronize folders =====
* copy the hardlinks inside the local machine (for backups of affa for ex.):
cp -a /source/folder /destination/folder
* copy the hard links from / to a remote machine (for backups of affa for ex.):
rsync -arPvH /source/folder root@IP:/destination/folder
* copy complete folder (incl. hidden files) via an archive:
* create the archive: ''tar cvfz archive.tar.gz /path-to folder-to-copy'' \\ **IMPORTANT:** make sure that you are **NOT** into the path that you want to copy!!
* move or copy the archive
* extract the archive:
cd /path-to-the folder where the archive is to extract
tar xvfz archive.tar.gz
Si il y a des problèmes mkstemp au niveau des permissions, il faut "no-perms":
# rsync -avz --no-perms --delete --progress root@machine.domain.tld:/dossier/de/source/ dossier_de_destination
Autre commande qui permet les interruptions et reprises de synchronisation:
# rsync -avh --progress --partial --append /source/folder root@IP:/destination/folder
===== Create from a partition a file ISO for a CDROM =====
sudo dd if=/dev/sdX of=/home/user/cdrom.iso bs=2048 conv=notrunc
===== Create a Freedos USB key =====
This is particularly needed to install drivers or to update a bios.
[[http://derek.chezmarcotte.ca/freedos-1-1-usb-boot-image|Source]]
* download the [[http://derek.chezmarcotte.ca/wp-content/uploads/2012/01/FreeDOS-1.1-USB-Boot.img.bz2|image]]
* extract the img. file bzip2 -d FreeDOS-1.1-USB-Boot.img.bz2
* copy the image on the USB key (check which device!) # dd if=FreeDOS-1.1-USB-Boot.img of=/dev/sdf
* mount the USB key # mount /dev/sdf1 /mount/point
* copy the drivers and bios etc... on the key#cp BIOS_UPDATE.EXE /mount/point
* umount the USB key
===== Creating a multiboot USB key: =====
My preferred solution is named "easy2boot".
The explanations for installation and use are for example here [[http://la-vache-libre.org/creer-une-cle-usb-multi-boot-en-6-etapes-avec-easy2boot-tuto/]] in french.
===== Deleting old kernels: =====
*for Ubuntu 10.04:
sudo apt-get remove linux-headers-2.6.32-67 linux-headers-2.6.32-67-generic linux-image-2.6.32-67-generic --purge
*for an OS with gnome2:
package-cleanup --oldkernels -count=2
*for Fedora >=22:the command "package-cleanup" is not available any more (belong to the package "yum-utils") but the number of remaining kernels can be set into "/etc/dnf/dnf.conf" with the parameter "installonly_limit=XX". Replace XX through the number of kernels you want to keep.
===== Desktop Mate: =====
When Mate doesn't display correctly its panel(the top bar with "applications", "places" and "system"), enter in a terminal to force Mate to regenerate the panel:
$ killall mate-panel
run the command automatically at login...
===== Erase the MBR =====
dd if=/dev/zero of=/dev/sdX bs=512 count=1
sdX or hdX or vdX or... = your disk!
===== Health of the hard drives =====
With the utility "Smartmontool":
* Get summary info about the disk by SMART:
sudo smartctl -H -i /dev/sdX
* Get complete info about the disk by SMART:
sudo smartctl -a /dev/sdX
* Run tests: \\ Two types of tests are at least available: the short one (~1-5 min.) and the long one (~10-150 min).
* Start the short test:
sudo smartctl -t short /dev/sdX
* Start the long test:
sudo smartctl -t long /dev/sdX
* Access afterwards to the results of the tests:
sudo smartctl -l selftest /dev/sdX
* Get briefly results (gives a message only by status "SMART failing" or if the autotests have reported errors)
sudo smartctl -q errorsonly -H -l selftest /dev/sdX
**Recognizing which drive is "sdX" get getting the serial number:**
hdparm -i /dev/sdX | grep -i serial
===== Information about the hardware =====
"lshw" or "dmidecode" or "hardinfo" in graphical mode
===== Information about parameters of php =====
http://php.net/manual/en/function.phpinfo.php \\ https://gestion.rapide.net/knowledgebase/33/Comment-creer-un-fichier-PHPINFO.html
===== Information about the present partitions =====
$ df -hT
Sys. de fichiers Type Taille Utilisé Dispo Uti% Monté sur
devtmpfs devtmpfs 3,9G 0 3,9G 0% /dev
tmpfs tmpfs 4,0G 4,0K 4,0G 1% /dev/shm
tmpfs tmpfs 4,0G 1,8M 4,0G 1% /run
tmpfs tmpfs 4,0G 0 4,0G 0% /sys/fs/cgroup
/dev/sda7 xfs 25G 17G 7,5G 70% /
tmpfs tmpfs 4,0G 32K 4,0G 1% /tmp
/dev/sda5 xfs 20G 12G 7,9G 60% /home
//Server_samba/shared_folder1 cifs 10G 8,2G 1,8G 82% /mount/point
===== Information about the RAM =====
$ free -t
total used free shared buffers cached
Mem: 2058028 1906956 151072 0 212940 764968
-/+ buffers/cache: 929048 1128980
Swap: 4104504 500 4104004
Total: 6162532 1907456 4255076
===== List services with their status =====
# service --status-all
===== Monitoring the system =====
"top" or "htop"
===== Info about the size of a directory =====
du -sh
===== Mass rename of files =====
Use the program called "metamorphose".
===== Mass changing permissions =====
For files and folders. $ find the_folder_to_set_permissions/ -type d -exec chmod 750 {} \;
$ find the_folder_to_set_permissions/ -type f -exec chmod 640 {} \;
Useful for manually installed web application.
===== Missing dependency =====
yum (or dnf) provides "the_name_of_the_missing_library"
will give which package must be installed to solve the missing dependency.
===== Mount a additional partition over the /etc/fstab file =====
must be tried and confirmed
* as explained in this[[http://askubuntu.com/questions/232790/automount-ext4-partition-with-user-permission-ownership-fstab|page]], setting /media/user as a mountpoint makes the partion appear in the files manager.
* permissions of the mountpoint:
* chmod 777 /the/mountpoint
* as described [[http://ubuntuforums.org/showthread.php?t=2176441|here]], setting a parameter "umask" allow to set permissions like 755
* [[https://doc.ubuntu-fr.org/mount_fstab|Documentation Ubuntu in french about "mount" and "fstab"]]
* The value to set for the umask / dmask or fmask is the value that must be substracted __BIT FOR BIT__ from 0777 (or 0666) to get the wished value for permissions: \\ eg: you want to set a chomd 755 => 0777 - 0755 = 0022 = the value for the umask \\ [[https://fr.wikipedia.org/wiki/Umask|wikipedia umask]]
===== Partition table for partitions larger than 2TB =====
MSDOS partition tables are OK for partitions smaller than 2TB. Larger partitions are automatically "cut" by 2TB. \\
For larger partitions, use "parted" instead of "fdisk" and set the type "GPT" for the partition type. \\
The alignment of the partitions is a little bit tricky with parted. \\
Following allows the creation of a partition on the whole disk:
# parted /dev/sdX
(parted) mkpart primary ext4 0% 100%
See [[https://wiki.archlinux.org/index.php/GNU_Parted]] too.
===== Renommer en masse =====
Pour renommer des fichiers en masse: utiliser ''gprename'' \\
Dispo sous Ubuntu 18.
Le lanceur ne se trouve pas dans le menu des applications => lancer "gprename" depuis un terminal.
===== Send the SSH key =====
$ ssh-copy-id -i ~USER_TO_CONNECT/.ssh/id_rsa.pub root@192.168.xxx.xxx
===== SSH connexion with key =====
$ ssh -i /path/of/the/key.rsa user@IP_of_remote_host
===== Symbolic links: =====
to create a symbolic links:
ln -s /path/of/the/source /path/of/the/link
===== Test network speed =====
Use "iperf" or "iperf3" https://doc.ubuntu-fr.org/iperf
===== Use of the command "visudo": =====
Visudo is used to edit and modify /etc/sudoers for example.
source: http://stackoverflow.com/questions/12736351/exit-save-edit-to-sudoers-file-putty-ssh
==== To make changes to sudo from putty/bash: ====
* Type visudo and press enter.
* Navigate to the place you wish to edit using the up and down arrow keys.
* Press insert to go into editing mode.
* Make your changes - for example: user ALL=(ALL) ALL.
It matters whether you use tabs or spaces when making changes.
* Once your changes are done press esc to exit editing mode.
* Now type '':wq'' to save and press enter.
You should now be back at bash. \\
Now you can press ctrl + D to exit the session if you wish.
===== Don't update a rpm with yum or dnf =====
yum --exclude=name_of_package* update
===== Users and groups =====
* list all users: cat /etc/passwd
or getent passwd
* list the groups the user is in: groups the_user
* list all groups: cat /etc/group
* add a user: adduser the_user #for complete adding (password + /home folder etc...) or
useradd #more simply
* add a group: addgroup the_goup
* delete a user:userdel the_user
===== ZFS =====
==== Delete all snapshots of a dataset ====
Delete all snapshots of dataset "DATASET":
# zfs list -H -t snapshot | grep "DATASET" | cut -f 1 | xargs -n 1 zfs destroy -r