⬅️ **[[$-Linux|Linux]]** *** [[Linux-Network]] ## General Tips - run command in background us `&` ## System Infos - `sudo systemctl -a` - `sudo service --status-all` - `df -h` - `sudo blkid` ## System Settings ### Repair Boot Manager `Boot-Repair` This tool solves the majority of bootsector/GRUB/MBR problems. [Sourceforge - Boot-Repair-Disk](https://sourceforge.net/p/boot-repair-cd/home/Home/){: .btn .btn--info } [Ubuntu - Boot-Repair](https://help.ubuntu.com/community/Boot-Repair){: .btn .btn--info } ### Timezone ``` mv /etc/localtime /root/localtime.old ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime ``` ## Access and Users Change the user's home directory: -d (abbreviation for --home) usermod -d /newhome/username username Change the user's home directory + Move the contents of the user's current directory: usermod -d -m /newhome/username username ### How to turn Off linux password expiration? `chage -l username` `chage -I -1 -m 0 -M 99999 -E -1 username` ### Chmod Permissions: - 1 – can execute - 2 – can write - 4 – can read ### Sudoers - `/etc/sudoers` ``` User privilege specification root ALL=(ALL:ALL) ALL tobi ALL=(ALL) NOPASSWD: ALL ``` ### [[SSH]] Erst tobi User muss sich mit SSH-Key anmelden können und in Sudoers eingetragen sein - Pre-requisites - SSH Public Key was already added with `ssh-copy-id` - This user is added to the `/etc/sudoers` file - Check the following settings in `/etc/ssh/sshd_conf` ``` PermitRootLogin no PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no ``` - give new users access by adding their public keys to the `~/.ssh/authorized_keys` ## Storage - Create folder and its path: `mkdir -p /home/tobi/some/new/folders` - `sudo iotop` to see what is writing on disk ### Partion, Format and Mount Drive ``` sudo fdisk -l sudo gdisk /dev/sdb ? - Help d - delete Partitions w - Write Partion Table sudo gdisk /dev/sdb n - new Partition -> All Default c - change Name -> enter new Partition Name w Filesystem Format sudo mkfs.ext4 /dev/sdb1 sudo blkid /dev/sdb1: UUID="9d4846d3-b4e3-4792-b0fe-dd346a70d484" TYPE="ext4" PARTLABEL="MCE-Data_Backup" PARTUUID="040c7ab9-cd72-4c4e-889f-5ece62e87ba9" /dev/sdb1: UUID="76d5b354-260f-4a5e-a505-9a70b5267deb" TYPE="ext4" PARTLABEL="MCE-Data_Backup" PARTUUID="7a80897b-742b-4778-8a76-e086372c5dc8" sudo nano /etc/fstab UUID=9d4846d3-b4e3-4792-b0fe-dd346a70d484 /mnt/MCE-Data ext4 defaults 0 0 UUID=76d5b354-260f-4a5e-a505-9a70b5267deb /mnt/MCE-Data_Backup ext4 defaults 0 0 sudo mount -a ``` ### HDD Idle ``` sudo apt install hd-idle sudo nano /etc/default/hd-idle START_HD_IDLE=true HD_IDLE_OPTS="-i 0 -a /dev/disk/by-uuid/76d5b354-260f-4a5e-a505-9a70b5267deb -i 1800 -l /var/log/hd-idle.log" Zur Erklärung: Die Zeile START_HD_IDLE=true sagt dem System, dass hd-idle als Daemon automatisch im Hintergrund gestartet werden soll. Die Option -i 0 sorgt dafür, dass nur Platten abgeschaltet werden, welche nach der Option -a aufgelistet sind. Die uuid bekommt man mit dem Befehl blkid heraus. Statt der uuid könnt ihr natürlich auch einen Pfad wie z.B. /dev/sda angeben, besser ist aber by-uuid, falls die Platte mal in einen anderen Port eingesteckt wird. Den Pfad bekommt man mit z.B. dem Befehl sudo fdisk -l heraus. Die Option -i 600 ist die Zeit in Sekunden bis zum abschalten, die Option -l ist für das Logfile. Nach einem Neustart sollte hd-idle automatisch im Hintergrund laufen und nach 10 Min. die Platte ausschalten, wenn sie denn unterstützt wird. Ob der Prozess nach dem Neustart im Hintergrund läuft sieht man mit ps aux | grep hd-idl, oder mit systemctl status hd-idle. Abschließend starten wir den hd-idle Daemon und verlinken diesen in den Autostart. sudo service hd-idle start sudo update-rc.d hd-idle defaults ``` ## Storage Infos - [tecmint - du command examples](https://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/) ```bash # get whole folder disk usage du -sh /folder ``` ### Rsync Backup with permissions 1. Edit `/etc/sudoers` file on the target machine to force rsync on the target machine to be run by `sudo rsync` ```bash # Command to local rsync binary Cmnd_Alias RSYNC = /usr/local/bin/rsync # Allow no password for the RSYNC command before for the specified user ssh-user ALL = NOPASSWD: RSYNC ``` 2. Use rsync on the source machine with the `--rsync-path` option ```bash # example rsync -a --rsync-path="sudo rsync" /usr/local/www [email protected]:/usr/backup_dir/ # final command: Copy ncp-data into the ncp-data-backup folder sudo rsync -vuar -P --rsync-path="sudo rsync" ncp-data tobi@server-tm:/datengrab/ncp-data-backup ``` ### Auto-mount Drives ```bash sudo mkdir /media/target sudo mount /dev/sda1 /media/target df -h sudo blkid /dev/sda1 # get UUID and TYPE sudo vim /etc/fstab # example line: UUID="a46e47a6-9260-46bc-8ef0-e914d7e8edab" /media/target ext4 defaults,nofail,noatime 0 0 # check sudo umount /dev/sda1 sudo mount -a # final check at restart sudo reboot df -h ``` ### SparkleShare ```bash # Run all of the following commands as the root user on # a Debian or Red Hat based Linux system su # Fetch the Dazzle script curl https://raw.githubusercontent.com/hbons/Dazzle/master/dazzle.sh \ --output /usr/bin/dazzle && chmod +x /usr/bin/dazzle # Run the initial setup dazzle setup # Link SparkleShare clients using their Client ID found in the status menu dazzle link # Create a new project. Add as many as you need dazzle create PROJECT_NAME ``` ## Network ### WLAN wpa_suplicant encryption - Config File: `/etc/wpa_supplicant/wpa_supplicant.conf` - Copy this output into the config file: ```bash tobi@pi-home:~ $ sudo wpa_passphrase <WLAN-Name> <Password> network={ ssid="<WLAN-Name>" #psk="<Password>" psk=<Encrypted_Password> } ``` ### DynDNS with ddclient NoIP Configuration for SelfHost are in the next section! - [NoIP](https://my.noip.com/) Account - Account E-Mail: ... - Domain: ... - Username: ... - Password: ... - Install `ddclient` ```bash sudo apt-get update sudo apt-get install ddclient libjson-any-perl # Just press enter and skip all insturctions ``` - Configure DynDNS Provider Settings: `/etc/ddclient.conf` ```bash # Configuration file for ddclient generated by debconf # # /etc/ddclient.conf use=web, web=checkip.dyndns.com/, web-skip='IP Address' ssl=yes # NoIP settings protocol=dyndns2 server=dynupdate.no-ip.com login=<username pf NoIP Account, not E-Mail Adress> password=<secret-password of NoIP Login> nolm.ddns.net ``` - Configure ddclient Service: `/etc/default/ddclient` ``` run_daemon="true" run_dhclient="false" run_ipup="false" ``` - Start ddclient as service ``` sudo service ddclient start sudo service ddclient status ``` - Manually start ddclient with `sudo /usr/sbin/ddclient -force` - Configure Daily CronJob to update IP Adress Change: `/etc/cron.daily/ddclient` ```bash #!/bin/sh /usr/sbin/ddclient -force echo "Last DynDNS Update with /etc/cron.daily/ddclient: $(date +'%A %F %T %Z')" > /home/mauritz/last-dyndns-update.txt ``` ### DynDNS with ddclient - SelfHost - see instructions above and the following SelfHost information [SelfHost - ddclient](https://www.selfhost.de/cgi-bin/selfhost?p=faq&show=113): - **DynDNS Accounte -> Liste -> Details -> Username, PW, Domain** ``` protocol=dyndns2 use=web, web-skip='IP Address' server=carol.selfhost.de login=ihr_dyndns_account password=ihr_passwort ```