Ubuntu Setup
Настройка Ubuntu OS
Учетные данные/доступ
Создание/Удаление sudo user
sudo useradd -m -s /bin/bash <user>
sudo usermod -aG sudo,adm,systemd-journal <user>
sudo passwd <user>
Удаление user + homedir
sudo pkill -u <user>
sudo userdel -r <user>
sudo visudo # Удалить строку <user>
Настройка SSH доступа
sudo apt install ssh -y
sudo rm /etc/ssh/sshd_config.d/50-cloud-init.conf # Для облачных образов
sudo tee /etc/ssh/sshd_config > /dev/null << 'EOF'
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 360
PermitRootLogin prohibit-password
PasswordAuthentication yes
PubkeyAuthentication yes
EOF
sudo systemctl restart ssh
Настройка Сети
Режим DHCP
sudo tee /etc/netplan/01-netcfg.yaml > /dev/null << 'EOF'
# DHCP
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
dhcp4-overrides:
use-dns: true
use-domains: true
dhcp6: false # Отключить IPv6 если не используется
EOF
Режим Static IP
sudo tee /etc/netplan/01-netcfg.yaml > /dev/null << 'EOF'
# Static IP
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses:
- 192.168.1.10/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
search: [local]
EOF
Перезапуск сети
sudo netplan apply
sudo systemctl restart systemd-networkd
Отключение ipv6
Способ 1 (Рекомендуемый)
sudo tee -a /etc/sysctl.conf > /dev/null << 'EOF'
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
EOF
sudo sysctl -p
sudo sysctl --system
Способ 2 (Через GRUB)
sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="ipv6.disable=1"/' /etc/default/grub
sudo update-grub
sudo reboot
Тюнинг системы
Изменение имени сервера
sudo hostnamectl set-hostname <name>
sudo tee -a /etc/hosts > /dev/null << 'EOF'
127.0.0.1 localhost <name>
::1 localhost <name>
EOF
Изменить Приветствие при User Logon
sudo chmod -x /etc/update-motd.d/10-help-text
sudo tee /etc/update-motd.d/10-help-text > /dev/null << 'EOF'
#!/bin/sh
# Файл очищен для изменения приветствия
EOF
Тюнинг Приглашения prompt в консоли
echo "PS1='\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]$ '" >> ~/.bashrc
source ~/.bashrc
Ограничение размера LOGs системы
sudo sed -i 's/#SystemMaxUse=/SystemMaxUse=100M/g' /etc/systemd/journald.conf
sudo systemctl restart systemd-journald
sudo journalctl --rotate
Добавление switch языка по Alt+Shift
# GNOME
sudo apt install gnome-tweaks -y
gsettings set org.gnome.desktop.input-sources xkb-options "['grp:alt_shift_toggle']"
Установка часового пояса (Москва)
sudo timedatectl list-timezones | grep Moscow
sudo timedatectl set-timezone Europe/Moscow
sudo localectl set-locale LC_TIME="ru_RU.UTF-8"
sudo locale-gen ru_RU.UTF-8
Смена раскладки (Ubuntu 24.04 Gnome)
sudo apt install gnome-tweak-tool -y
gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['<Super>space']"
gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward "['<Shift><Super>space']"
Ярлык для Desktop OS
tee ~/Desktop/myapp.desktop > /dev/null << 'EOF'
[Desktop Entry]
Version=1.0
Name=MyApp
Comment=My Application
Exec=/path/to/script.sh
Icon=/path/to/icon.png
Terminal=false
Type=Application
Categories=Utility;
EOF
chmod +x ~/Desktop/myapp.desktop
Обновление системы, Алиасы
Установка доп. пакетов
sudo apt update
sudo apt install -y vim tree net-tools mlocate curl wget htop jq
Добавление Алиасов/Обновления
tee -a ~/.bashrc << 'EOF'
# ------------------------------------------------------------------------------
# Prompt console
# ------------------------------------------------------------------------------
PS1='\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]$ '
# ------------------------------------------------------------------------------
# Bind Aliases
# ------------------------------------------------------------------------------
alias upd='sudo apt update -y && \
sudo apt upgrade -y && \
sudo apt full-upgrade -y && \
sudo apt autoremove -y && \
sudo apt autoclean -y && \
sudo updatedb && \
sudo apt --fix-broken install'
alias hclean='cat /dev/null > ~/.bash_history && history -c'
alias doc='docker ps --all --format "table {{.ID}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}"'
alias ports='sudo netstat -tulpn | grep LISTEN'
# ------------------------------------------------------------------------------
EOF
source ~/.bashrc
Дополнительные настройки для Ubuntu 24.04
# Включение автоматических обновлений безопасности
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades
# Настройка временной зоны для журналов
sudo timedatectl set-local-rtc 0
# Оптимизация SWAP
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
# Настройка лимитов системы
sudo tee -a /etc/security/limits.conf > /dev/null << 'EOF'
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
EOF
Настройка fail2ban для SSH
sudo apt install fail2ban -y
sudo tee /etc/fail2ban/jail.local > /dev/null << 'EOF'
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
EOF
sudo systemctl enable fail2ban
sudo systemctl start fail2ban