Linux Optimizer
This Bash script automates the optimization of your Linux server.
It performs the following tasks:
-
Set the server TimeZone to Asia/Tehran.
-
Update, Upgrade, and Clean the server:
- Update
- Upgrade
- Dist-Upgrade
- AutoRemove
- AutoClean
- Clean
-
Install Useful Packages:
apt-transport-https
apt-utils
autoconf
automake
bash-completion
bc
binutils
binutils-common
binutils-x86-64-linux-gnu
build-essential
busybox
ca-certificates
cron
curl
dialog
epel-release
gnupg2
git
haveged
htop
iptables
iptables-persistent
jq
keyring
libssl-dev
libsqlite3-dev
libtool
locales
lsb-release
make
nano
net-tools
nftables
packagekit
preload
python3
python3-pip
qrencode
socat
screen
software-properties-common
ufw
unzip
vim
wget
zip
-
Enable Packages at Server Boot.
-
Create & Enable
SWAP
File:- Swap Path:
"/swapfile"
- Swap Size:
2Gb
- Swap Path:
-
Enable
IPv6
Support. -
Optimize the
SYSCTL
Configs.- Optimize
SWAP
. - Optimize Network Settings.
- Activate
BBR
. - Optimize the Kernel.
Original file is backed up at
/etc/sysctl.conf.bak
. - Optimize
-
Optimize
SSH
:- Back up the original
sshd_config
file. - Disable DNS lookups for connecting clients.
- Remove less efficient encryption ciphers.
- Enable and Configure TCP keep-alive messages.
- Allow agent & TCP forwarding.
- Enable gateway ports, Tunneling & Compression.
- Enable X11 Forwarding.
Original file is backed up at
/etc/ssh/sshd_config.bak
. - Back up the original
-
Optimize the System Limits:
- ulimit
-c -d -f -i -n -q -u -v -x -s -l
optimizations. - Soft & Hard
nproc
limits. - Soft & Hard
nofile
limits.
- ulimit
-
Optimize
UFW
& Open Common Ports.- Open Ports
21
,22
,80
,443
. - With
IPv6
,TCP
&UDP
.
- Open Ports
Reboot at the end is Recommended.
Pre-Run
wget
and sudo
must be installed.
Packages - Ubuntu & Debian:
apt install -y sudo wget
- CentOS & Fedora:
dnf install -y sudo wget
Run
Tested on: Ubuntu 18+, Debian 11+, CentOS 8+, Fedora 37+
Root Access is Required. If the user is not root, first run:
sudo -i
Then:
wget "https://raw.githubusercontent.com/hawshemi/Linux-Optimizer/main/linux-optimizer.sh" -O linux-optimizer.sh && chmod +x linux-optimizer.sh && bash linux-optimizer.sh
Menu Image
Disclaimer
This script is provided as-is, without any warranty or guarantee. Use it at your own risk.
License
This script is licensed under the MIT License.