Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Last active August 28, 2023 11:28
Show Gist options
  • Save vhbui02/8131c596ccdd79c4c5d8bc9561dbffdc to your computer and use it in GitHub Desktop.
Save vhbui02/8131c596ccdd79c4c5d8bc9561dbffdc to your computer and use it in GitHub Desktop.
[Linux cheatsheet] Very very many trivial things

Table of contents

I create a custom GitOpenSourceApps, AppImagesApplication in home folder

Duplicate /snap/bin directory in $PATH remove

https://askubuntu.com/questions/1349900/duplicate-system-path-variable-snap-bin-snap-bin

systemctl

  • Start on boot sudo systemctl enable <service>
  • Disable perminent sudo systemctl disable <service>
  • Start (reset after login) sudo systemctl start <service>

Fish

  • Remove greeting set -U fish_greeting
  • Print current OS type $(uname)
  • Print status code $status (in bash, it's $?
  • Set $EDITOR to gedit to be used when ran funced
  • Break long-line command Alt+Enter

Some trivial things I learn when learning Fish shell

  • print default shell echo $SHELL
  • list all shells installed cat /etc/shells
  • change default shell chsh -s /usr/bin/fish (remember to log out to see effect)

MySQL

  • Check authentication method for each MySQL user accounts SELECT user,authentication_string,plugin,host FROM mysql.user;
  • Create new user CREATE USER 'sammy'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
  • Change user auth method ALTER USER 'sammy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
  • Grant privileges GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;

systemctl

  • Check systemctl is-active <service_name>

Identify IP

  • ip a
  • ip addr show <network_interface> | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

ufw

  • Enable sudo ufw enable

  • Disable sudo ufw disable

  • Reset sudo ufw reset (fresh start, disable and remove all custom rules)

  • Check status sudo ufw status [verbose] [numbered]

  • Allow/Deny sudo ufw allow/deny <port>

  • Allow/Deny by name defined in /etc/services sudo ufw allow/deny <service_name>

  • Delete by number sudo ufw delete <num>

  • Delete by actual rule sudo ufw delete allow ssh

Ref: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-22-04

ssh

  • Begin SSH-ing ssh <user-name>@<ip address>
  • Enable service sudo systemctl start ssh
  • Check service sudo systemctl status ssh
  • Disable service sudo systemctl disable --now ssh
  • Re-enable service sudo systemctl enable --now ssh
  • Restart service sudo systemctl restart ssh
  • Open SSH port via ufw sudo ufw allow ssh
  • Generate SSH key ssh-keygen -t rsa -b 4096 -C "some comment" (ssh-keygen generate default RSA-3072)
  • Automatic add SSH key ssh-copy-id <user_name>@<server_IPaddress>
  • Manual add SSH key cat ~/.ssh/id_rsa.pub | ssh user_name@server_ipaddress "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
  • Check SSH key ls ~/.ssh/id_*
  • Disable SSH password authentication In sshd_config, set PasswordAuthentication no

Ref:

tmux

Prefix hotkey Ctrl+b

  • List running sessions tmux ls (or tmux list-sessions)

  • New session with name tmux new -s <session-name>

  • Attach to session tmux attach -t <session-name>

  • Kill session tmux kill-session -t <session-name>

  • Detach from session Ctrl+b then D

  • Create new win Ctrl+b then C

  • Cycle prev win Ctrl+b then P

  • Cycle next win Ctrl-b then N

  • Kill current win Ctrl-b then & (or just exit)

  • Manual select wins Ctrl-b then W

  • Rename Ctrl-b then ,

  • Split ver Ctrl-b then %

  • Split hor Ctrl-b then "

  • List keybindings Ctrl-b then ?

  • Type command Ctrl-b then : (e.g. to split var, use split-screen, to split hor, use split

Ref: https://gist.github.com/andreyvit/2921703

git

  • Clone a specific tag git clone --depth 1 --branch <tag_name> <repo_url> NOTE: --depta 1 is optional, only used when need the state at the 1 revision, no download history. Some people downloads whole history for nothing :v Ref: https://stackoverflow.com/a/24102558

Diffrence between bashrc and bash profile

https://superuser.com/questions/183870/difference-between-bashrc-and-bash-profile/183980#183980 (24/08/23)

The meaning of $-

https://stackoverflow.com/questions/42757236/what-does-mean-in-bash (23/08/23)

The meaning of i)

https://stackoverflow.com/questions/40747576/need-help-understanding-a-strange-bashrc-expression (23/08/23)

flatpak

snap

  • Search snap find <package_name>
  • Install sudo snap install <package_name>
  • List install snap list
  • List install + Old package snap list --all (reveal old ver marked as disabled)
  • Get info snap info <package_name>
  • Uninstall sudo snap remove <package_name> --purge
  • Uninstall + Delete snap shot sudo snap remove <package_name> --purge
  • Uninstall disabled package sudo snap remove <package_name> --revision=<rev name>

AppImageLauncher

  • Desktop entry files ~/.local/share/applications

Terminal

https://askubuntu.com/questions/3167/what-is-difference-between-the-options-autoclean-autoremove-and-clean -sudo apt remove --purge <package_name> -sudo apt autoclean -sudo apt clean -sudo apt autoremove

Keyboard remapping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment