linux_cheatsheet
(last updated: 7.11.2021)
Misc
list details of folder
ls -l
delete folder and all internal files / folders
rm -rf <folder>
mount share on synology from another linux computer
sudo mount -t cifs //192.168.1.169/video /mnt/hankvault -o username=gpa,vers=2.0
-make sure to create the mount folder first
-may have to adjust version
-may have to add line into /etc/fstab, likely just once for each server added, not each share
enable automatic security updates on Ubuntu:
dpkg-reconfigure -plow unattended-upgrades
command line checksum of downloaded files:
echo "5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931 *ubuntu-22.04.2-live-server-amd64.iso" | shasum -a 256 --check
tar-gzip
tar-gzip a file
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
untar-gzip a file
tar -xzvf archive.tar.gz
exclude files while tarring
tar --exclude='/exclude/this/dir' --exclude='/exclude/this/dir2' -czvf tarfile.tar.gz /dir-or-file/to/tar/
SCP
scp local file to remote server directory:
scp file.txt remote_username@10.10.0.2:/remote/directory
scp local DIRECTORY to remote server directory:
scp -r /local/directory remote_username@10.10.0.2:/remote/directory
scp remote file to local directory:
scp remote_username@10.10.0.2:/remote/file.txt /local/directory
scp remote directory to local directory:
scp -r remote_username@10.10.0.2:/remote/directory /local/directory
command line for finding public IP address
dig +short myip.opendns.com @resolver1.opendns.com
remove execute permission from all files in a directory
chmod -x *
remove execute permission from all files recursively in a directory
chmod -R -x <directory_name>
find the bluray drive sg number
sg_map -a
SSH
create ssh keys and push to server
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
Copy your id_rsa.pub to another machine’s ~/.ssh/authorized_keys/ for
passwordless ssh
ssh-copy-id remote_username@server_ip_address
Add a server’s fingerprint to your client’s known_hosts file:
ssh-keyscan -H 192.168.1.162 >> ~/.ssh/known_hosts
Change ownership of folder and all contents within:
sudo chown -R mary ./archive/
Change ownership of folder and all contents within with new user group:
sudo chown -R mary:mary ./archive/
Get IP address of domain:
dig A <domain>
Encrypt/Decrypt a file using SSL
openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -in file.test -out file.test.openssl
openssl enc -aes-256-cbc -d -md sha512 -pbkdf2 -iter 100000 -salt -in file.test.openssl -out file.test
Encrypt/Decrypt a file using GPG (supposedly a better option than SSL)
gpg --output encrypted.data --symmetric --cipher-algo AES256 --no-symkey-cache un_encrypted.data
gpg --output un_encrypted.data --decrypt encrypted.data
Verify File with GPG
- Download files
- Run GPG’s fetch-keys command to import the projects’ public key from keyserver (like Keybase.io), into your computers keychain:
gpg --fetch-keys https://keybase.io/<USER_ALIAS>/pgp_keys.asc
- Verify the signature file (the file may end in .sig or .asc)
gpg --verify <FILE_NAME>.amd64.deb.asc
- If you have a shasum file, check it with this:
shasum -a 256 --ignore-missing --check <FILE_NAME>.sha256.txt
Add a “lazygit” function to bash
- add the following to ~./bashrc
function lazygit() {
git add .
git commit -m “$1”
git push -u origin master
}
- then use command:
source ~/.bashrc
Anaconda
Start Anaconda command line environment: conda activate
Start Anaconda Navigator/GUI: anaconda-navigator
Start Spyder: conda activate
, then spyder
Exit Anaconda terminal environment: conda deactivate
SMB mount location on Pop!_OS: /run/user/*UID*/gvfs/
Restic
backup:
restic -r rest:http://LOCALIP:8000/REPONAME backup /home/XXXX --exclude-file='/home/XXXX/.restic/exclude.txt'
snapshots:
restic -r rest:http://LOCALIP:8000/REPONAME snapshots
forget/prune:
restic -r rest:http://LOCALIP:8000/REPONAME forget --keep-last 12 --prune
Disk Resizing
https://askubuntu.com/questions/498709/how-can-i-resize-an-active-lvm-partition
ZFS
list all snapshots:
zfs list -t snapshot