Linux

Linux Awesome Notes

How to change SSH port

sudo nano /etc/ssh/sshd_config

Port 2222 # Change 2222 to your desired port number

sudo systemctl restart ssh
# or
sudo systemctl restart sshd


sudo ufw allow 2222/tcp # If using UFW firewall, allow the new port
 

How to copy one whole dir from one server to another

rsync -avz -e ssh /home/onedir/ user@ip:/home/onedir/

Where:

  • -a preserves all file attributes (permissions, timestamps, ownership, etc.)
  • -v shows the copying progress (verbose mode)
  • -z enables compression during transfer
  • -e ssh specifies to use SSH for transfer

How to switch on fail2ban

# Initial setup
touch /var/log/f2ban.log
sudo apt update && sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban

# Create and edit config
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local

# Add to jail.local:
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/f2ban.log
maxretry = 5

# Restart and check
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

# To unban IP:
sudo fail2ban-client unban IP_ADDR

Переместить все файлы и директории в другое место

sudo rsync -avh --remove-source-files --recursive --prune-empty-dirs /var/www/sg.sg1/ /var/www/sg.docker/sg1src

или

sudo cp -rp /var/www/w3/x/dir /var/www/w3/
sudo rm -rf /var/www/w3/x/dir

Эти команды:

  1. Рекурсивно копируют директорию  /var/www/w3/x/dir со всем содержимым и правами доступа в /var/www/w3/dir.
  2. Удаляют исходную директорию /var/www/w3/x/dir.

Обратите внимание, что опция -p (--preserve) в команде cp также сохраняет права доступа при копировании.

Как рекурсивно изменить все права на директорию ?

sudo chmod -R ugo+rw /DATA/SHARE

chmod – the command to modify permissions
-R – this modifies the permission of the parent folder and the child objects within
ugo+rw – this gives User, Group, and Other read and write access.

 

Добавить пользователя user в группу supergroup:

usermod -a -G supergroup user

 

Отличный просмотрщик использования дисков ncdu

sudo apt update

sudo apt install ncdu

пример использования

ncdu .

 

Получить список файлов по дате создания с абсолютными путями 

 

find "$PWD" -type f -newermt "2020-02-10 17:55:00" ! -newermt "2020-02-10 18:30:00" -ls

 

Full details from man find:

   -newerXY reference
          Compares the timestamp of the current file with reference.  The reference argument is normally the name of a file (and one of its timestamps  is  used
          for  the  comparison)  but  it may also be a string describing an absolute time.  X and Y are placeholders for other letters, and these letters select
          which time belonging to how reference is used for the comparison.

          a   The access time of the file reference
          B   The birth time of the file reference
          c   The inode status change time of reference
          m   The modification time of the file reference
          t   reference is interpreted directly as a time

          Some combinations are invalid; for example, it is invalid for X to be t.  Some combinations are not implemented on all systems; for example B  is  not
          supported on all systems.  If an invalid or unsupported combination of XY is specified, a fatal error results.  Time specifications are interpreted as
          for the argument to the -d option of GNU date.  If you try to use the birth time of a reference file, and the birth time cannot be determined, a fatal
          error  message  results.   If  you  specify a test which refers to the birth time of files being examined, this test will fail for any files where the
          birth time is unknown.
 

 

КАК СМЕНИТЬ ПАРОЛЬ ДРУГОГО ПОЛЬЗОВАТЕЛЯ

passwd user

Тотальная переустановка пакета

 

Правильное удаление SWAP файлов

  1. First, deactivate the swap by typing:

    sudo swapoff -v /swapfileCopy
  2. Remove the swap file entry /swapfile swap swap defaults 0 0 from the /etc/fstab file.

  3. Finally, delete the actual swapfile file using the rm command:

    sudo rm /swapfile

 

Как замерить потребление оперативной памяти в мегабайтах

ps axo pid,user,comm,rss | awk '{print $1,$2,$3,$4/1024 " MB"}' | sort -rnk4 | head -n 20
Афоризм дня:
Кто спрашивает, почему нам приятно водиться с красивыми людьми, тот слеп. (611)

Leave a reply

Яндекс.Метрика