Linux Initialization

Linux Initialization


“Execute all steps with a single command.”

1
bash -c "$(wget -qLO - https://apps.kingtam.eu.org/scripts/linux-init.sh)"

Compatible only with Debian or Ubuntu.


Install Packages (Step by step)

Install all the packages through apk

1
sudo apt update && sudo apt -y install git wget curl tree iperf3 vim tmux

Adding a user named tkk

as an example, enter the command to add a user, add a user directory, and specify bash as the shell.

1
useradd -m -s /bin/bash tkk

If you don’t want to enter sudothe password every time, you can set it to be password-free.

1
tee /etc/sudoers.d/tkk <<< 'tkk ALL=(ALL) NOPASSWD: ALL'

Finally grant the correct permissions:

1
chmod 440 /etc/sudoers.d/tkk

Linux Terminal Tab Completion

In fact, this command can be used to do it all.

1
2
3
4
cat >> ".inputrc" << EOF
set completion-ignore-case on
set show-all-if-ambiguous on
EOF

Get the public key from Github:

1
bash <(curl -fsSL git.io/key.sh) -g sillydanny

Install VIM-PLUG on Linux

  1. Download plug.vim and put it in the “autoload” directory.
1
2
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  1. Add a vim-plug section to your ~/.vimrc.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cat >> ~/.vimrc << EOF
call plug#begin()
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-commentary'
Plug 'scrooloose/nerdtree'
Plug 'joshdick/onedark.vim'
Plug 'octol/vim-cpp-enhanced-highlight'
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Keyboard mapping to toggle the nerdtree file explorer.
nnoremap <F5> :exec 'NERDTreeToggle' <CR>
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
" Set colorscheme
set background=dark
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
" Enable status bar color
set t_Co=256
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim Airline themes
let g:airline_powerline_fonts=1
let g:airline#extensions#tabline#enabled=1
" Vim Cpp Highlight
let g:cpp_class_scope_highlight=1
let g:cpp_member_variable_highlight=1
let g:cpp_experimental_simple_template_highlight=1
let g:cpp_concepts_highlight=1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType toml,txt,c,cpp,cs,java,kotlin,yaml,apache setlocal commentstring=#\ %s
EOF
  1. Reload .vimrc and install plugins.

Open vi editor

1
:PlugInstall

Customizing Tmux

Customize Tmux by editing its configuration file, typically located at ~/.tmux.conf. Here’s an example of a simple configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
cat << EOF > ~/.tmux.conf
## Change the prefix key to Ctrl + a (easier to reach than Ctrl + b)
# unbind C-b
# set-option -g prefix C-a
# bind C-a send-prefix

# Enable mouse support (for scrolling, resizing panes, etc.)
set -g mouse on

# Set the status bar to the top
set-option -g status-position top

# Use a more visually appealing status bar
set -g status-bg colour235
set -g status-fg white
set -g status-left-length 50
set -g status-right-length 50

# Reload the config file with Ctrl + a, then r
bind r source-file ~/.tmux.conf \; display "Reloaded ~/.tmux.conf"

# Start window and pane numbering at 1 (easier to switch to)
set -g base-index 1
setw -g pane-base-index 1

# Use vi mode for copy-paste (useful for vim users)
setw -g mode-keys vi

# Easier window navigation
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R

# Resize panes more easily
bind-key -r H resize-pane -L 5
bind-key -r J resize-pane -D 5
bind-key -r K resize-pane -U 5
bind-key -r L resize-pane -R 5

# Automatically renumber windows when one is closed
set-option -g renumber-windows on

# Increase scrollback buffer size
set -g history-limit 10000

# Enable true color support (for better colors in terminal)
set -g default-terminal "screen-256color"
set-option -ga terminal-overrides ",xterm-256color:Tc"

EOF

After making changes, reload the configuration with:

1
tmux source-file ~/.tmux.conf

Mount a Hard Drive in Linux on Startup

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/bash

# Create /media directory if it doesn't exist
if [ ! -d "/media" ]; then
  sudo mkdir -p /media
fi

# Get the UUID from /dev/disk/by-uuid/
uuid=$(ls -l /dev/disk/by-uuid/ | grep -i 'sda' | awk '{print $9}')

# Add the UUID to /etc/fstab
echo "UUID=\"$uuid\"     /media  ext4    defaults,errors=remount-ro 0 1" >> /etc/fstab

The NR==3 condition in the awk command ensures that only the third line is selected. The echo command appends a new line to /etc/fstab with the desired format, using the extracted UUID.


Options

https://docs.docker.com/engine/install/ubuntu/

https://kingtam.eu.org/posts/rsync-usage/

https://kingtam.eu.org/posts/rsync-windows/

https://kingtam.win/archives/samba.html