# Bash # Quick commands ### Change owner of folder ```bash sudo chown -R : ``` ### Manage Linux groups #### Create group ``` groupadd ``` #### Add user to group ```bash usermod -a -G ``` #### List groups ``` sudo groups -la ``` ### Managing tar files #### Preview content of tar file ```bash tar -tzf ``` #### Extract content of tar file ```bash tar -xzf ``` ### Copy files and folders ```bash cp -r ``` ### SCP ```bash scp @: ``` ### Get folder size ```bash du -s ``` ### Get task manager view ``` SAR ``` ``` TOP ``` ### Move foreground job to background CTRL + Z bg -> Move job to background fg -> Move job to foreground ### Generate SSH key ```bash ssh-keygen -t rsa -b 4096 -C "" -f .ssh/ ``` ### Apt remove insecure repositories ```bash sudo apt autoremove ``` ### Replace characters in file ``` sed -i 's///g' ``` ### Sync clock ```bash sudo hwclock -s ``` ## Resolve DNS Server ### Set dns server on specific interface ``` sudo systemd-resolve --set-dns= --interface= ``` # Allow ssh with password ### Change parameter in config file Edit ssh config file: ```bash sudo nano /etc/ssh/sshd_config ``` [![image.png](https://docs.lucanoahcaprez.ch/uploads/images/gallery/2022-12/scaled-1680-/Grkimage.png)](https://docs.lucanoahcaprez.ch/uploads/images/gallery/2022-12/Grkimage.png) ### Restart ssh service ```powershell sudo systemctl restart sshd ``` # Increase diskstorage for Linux VMs To increase the storage drive you first have to increase the storagecapacity in the proxmox admin gui. Then you can use the following commands in this order to increase the size of the volume. ```bash fdisk -l ``` ``` cfdisk ``` Next choose "Resize" and then "Write". ```bash fdisk -l #example path: /dev/sda ``` ```bash parted ``` Next choose "print" -> "Resizepart". Enter number of device. Then choose "quit". ``` pvresize ``` ``` lvextend -l +100%FREE ``` ``` resize2fs ``` ``` df -h ``` Then reboot the machine. # Make script executable In order to make sure that a file ending in .sh can be executed, you have to change its permissions. This is necessary if a script is to be executed by an automation like Ansible or Crontab. ```bash chmod +x /path/to/yourscript.sh ``` Afterwards it can be called by its relative or absolut path. Sometimes you have to specify the interpreter path such as /bin/bash. ```bash /path/to/yourscript.sh ``` ``` ./yourscript.sh ``` ```bash /bin/bash /path/to/yourscript.sh ``` # Backup MongoDB Docker container via Bash script This short script is to backup a MongoDB database inside a docker container. A command is executed inside the Docker container via "docker exec". The command uses the program "mongodump", which is already installed on most container images. There you can specify the path in the Docker container where the backup should be stored. Here it is important that the folder in the Docker container is mapped to the filesystem of the host. ```bash datetmp=$(date '+%Y%m%d') dateprod=${datetmp:2} docker exec /bin/sh -c "mongodump --host="localhost:27017" --port=27017 -o '/data/backups/${dateprod} backup'" ``` This script can be executed regularly by means of a cronjob, so that the backups are available at a regular interval. Instructions for creating a cronjob can be found here: [Quick commands | LNC DOCS (lucanoahcaprez.ch)](https://docs.lucanoahcaprez.ch/books/cron/page/quick-commands)