Here’s a collection of useful Linux tips and tricks that have improved my workflow throughout my career. I will continue to update this post as I come across more awesome techniques.
Table of Contents
Open Table of Contents
Fish
Why use fish?
- You get to tell your friends you use fish and not bash
To change the current shell to fish, run the following:
echo /usr/local/bin/fish | sudo tee -a /etc/shells && chsh -s /usr/local/bin/fish
Installing omf
Next, install omf.
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish
Setting up a theme
Personally, I like to use the coffeandcode.
omf install coffeeandcode
omf theme coffeeandcode
Adding the time to the fish prompt
Sometimes it’s nice to have timestamps for your commands. Find fish_prompt.fish
for your current
theme:
find / -name "fish_prompt.fish" 2>/dev/null
Prepend the echo
line associated with your fish prompt with (date +%H:%M) ' '
:
echo -s (date +%H:%M) ' ' (whatever-your-fish-prompt-is)
The echo
command may be different depending on which theme you are using.
Configuring aliases
To configure aliases, run the following in the fish shell:
# This will run rm -i your-argument, mind the space between "-i" and "your-argument"
alias rmi "rm -i" --save
# For a bit more complex stuff (no space after command)
function new-folder
mkdir /opt/project-$argv
end
funcsave new-folder
Some aliases I’ve used:
# Basically a proxychains shortcut
alias pxc 'proxychains -q' --save
# Search history for keywords
alias hg 'history | grep' --save
# I stole this from reddit
alias myip 'ip addr show eth0 | grep -oP "(?<=inet\s)\d+(\.\d+){3}"' --save
# Opens up chromium with a google search appended
# Usage: gsearch "what is love"
function gsearch
chromium https://www.google.com/search\?q=$argv
end
funcsave gsearch
Tmux
Install tmux:
sudo apt install tmux
Start new tmux session with name:
tmux new -s mysession
Attach to a named tmux session:
tmux a -t mysession
List sessions:
tmux ls
Kill a session:
tmux kill-session -t mysession
Tmux shortcuts to know
- Default prefix:
Ctrl
+B
- Create new window:
Ctrl
+B
->c
- Split window into two vertical panes:
Ctrl
+B
->%
- To remember: imagine a vertical line going down from the
%
key on your keyboard
- To remember: imagine a vertical line going down from the
- Split window into two horizontal panes:
Ctrl
+B
->"
- To remember: imagine a horizontal line going left from the
"
key on your keyboard
- To remember: imagine a horizontal line going left from the
- Switch between windows:
Ctrl
+B
-> Window # - Switch between panes:
Ctrl
+B
-> Arrow key - List sessions:
Ctrl
+B
->s
- Detach from current session:
Ctrl
+B
->d
- Create new session from existing session:
: new -s mysession
- Save tmux output:
:capture-pane -S -
:save-buffer filename.txt
Tmux plugins
Install tmux plugin manager:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add this to the bottom of ~/.tmux.conf
:
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin '[email protected]:user/plugin'
# set -g @plugin '[email protected]:user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
To install plugins:
Add plugin into ~/.tmux.conf
:
set -g @plugin myplugin
Then run Ctrl
+ B
-> I
to install.
To uninstall, run Ctrl
+ B
> Alt
+ u
.
Tmux config file
My personal config file:
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'catppuccin/tmux'
set -g @nova-nerdfonts false
set -g base-index 1
set -g history-limit 50000
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
Here’s a cool example of another from a buddy of mine.
Python virtual environments
Python virtual environments save lives. Run the following before installing packages from a
requirements.txt
file:
python3 -m venv my-venv-name
source my-venv-name/bin/activate.fish
Neovim
Neovim is another cool tool I’ve began to use a bit more. There are precompiled binaries out there, but since I’m on an ARM64-based Kali VM, I had to install from source.
Install dependencies:
sudo apt-get install ninja-build gettext cmake unzip curl build-essential
Select the Release build:
make CMAKE_BUILD_TYPE=Release
Install with CMake:
sudo make install
NvChad
Install NvChad:
git clone https://github.com/NvChad/starter ~/.config/nvim && nvim
You may want to install ripgrep as well.
Some extra configuration stuff:
"" Make it so that Insert Mode displays relative line numbers only
autocmd InsertEnter * :set relativenumber
autocmd InsertLeave * :set norelativenumber
"" Make it so that hitting "Esc" sets mode to Normal Terminal in a Nvim Terminal
tnoremap <Esc> <C-\><C-n>
Some keyboard shortcuts / commands to remember:
General vim stuff:
- Move one word to the right:
w
- Move one word to the left:
b
- Delete current line:
dd
- Move to first line of file:
gg
- Move to last line of file:
G
- Move to first non-blank character in line:
^
- Move to last non-blank character in line:
g_
- Move to beginning of line:
0
- Move to end of line:
$
- Delete all trailing whitespace in line:
g_lD
- Delete current line and go into insert mode:
S
- Go to insert mode at beginning of line:
I
- Change inside ” or (:
ci"
orci(
- Delete paragraph:
dap
To modify the beginning/end of multiple lines (useful for commenting out multiple lines)
Ctrl
+v
to block-select lines to editI
to edit beginning of line, or$A
to edit the end of line- After editing, press
Esc
and watch the magic
NvimTree:
- Toggle NvimTree:
Ctrl
+n
- Move from editor to NvimTree:
Ctrl
+h
orSpace
+e
- Move from NvimTree to editor:
Ctrl
+l
- Hide/reveal hidden files:
H
- Expand file tree:
E
- Collapse file tree:
W
- Open file in new buffer:
Enter
- Open file but don’t go to new buffer:
Tab
- Add a file:
a
- Rename a file:
r
- Delete a file:
d
- Copy and paste a file:
c
andp
- Copy filename to clipboard:
y
Tabs:
- Navigate tabs:
Tab
orShift
+Tab
- Copy selection to system clipboard:
"
->+
->y
- Copy entire file to system clipboard:
:%+y
- Open up a terminal:
Space
->h
- Close tab without hiding the other ones:
Space
->x
Searching:
- Search files:
:Telescope fd
- Search for files that contain a certain string:
:Telescope live_grep <string>
(requires ripgrep)
Other stuff:
- Select theme:
Space
->t
->h
7za
To add files to archive:
7za a myfiles.zip *
To extract an archive to a specific directory:
7za x myfiles.zip -o/path/to/directory
Install common tooling
I made a tool called kali-on-command that uses Ansible to install some common tools for red team operations. It’s primarily meant for Red vs. Blue Team competitions but can be used for general red teaming purposes.
# Install dependencies
apt -y update
apt -y install ansible-core sshpass
ansible-galaxy collection install community.general
# Clone git repo
git clone https://github.com/fyrworx4/kali-on-command.git
cd kali-on-command
# Run playbook
ansible-playbook -c local -i localhost, playbook.yml
References
- https://stackoverflow.com/questions/2762994/define-an-alias-in-fish-shell
- https://www.reddit.com/r/Hacking_Tutorials/comments/ncb22y/useful_bash_aliases_for_ethical_hackingpen_testing/
- https://gist.github.com/MohamedAlaa/2961058
- https://tmuxcheatsheet.com/
- https://docs.rockylinux.org/books/nvchad/nvchad_ui/using_nvchad/