• Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / Linux sysadmin tutorials linux system administrator / change ssh port in linux – avoid sshd ddos attacks

change ssh port in linux – avoid sshd ddos attacks

change ssh port in linux in following steps, are you getting lot of bot flood traffic, high cpu usage due to default ssh port 22 in linux, then change the ssh port in linux and get sae server costs, and scale your linux server by simply changing the linux ssh port.

 

with default port 22

sshd Invalid user from port  33378

 

first allow New Port in linux firewall & cloud provide firewall

ex: my case added digitalocean firewall.

 

Table of Contents

Toggle
  • Check well known ports choose from (1024 to 65535)
  • add new SSH port to linux firewall allow list
  • edit openssh  in ubuntu debian linux distro
  • Change default ssh port 22 to new port
  • #2 change ssh port in linux – restart sshd or ssh server – #
  • Check SSH server listening newport or not
  • Login with New Port  – change ssh port in linux
    • Block Port 22 Using UFW Firewall – change ssh port in linux
  • Block Port 22 using  digitalocean firewall
  • Check linux auth  syslogs get rid of ddos attacks
    • Summary on changing ssh linux port

Check well known ports choose from (1024 to 65535)

ssh brute force
sshd Invalid user from port
source port was 4627, the destination port was 2221
sshd blocked login by disconnecting the tcp connection
port number given in the log is the port on the client side, not on yours.
change SSHD port 21 to other
firewall rule block or drop
allow new port after successful login block old port 22.
choose any port between  1024 to 65535
 

add new SSH port to linux firewall allow list

 
sudo ufw allow 20482/tcp
sudo ufw allow ssh
 
sudo ufw app list
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH
 

edit openssh  in ubuntu debian linux distro

you can use nano or vim command.
nano /etc/ssh/sshd_config
CTRL+X to exit and save changes

Change default ssh port 22 to new port

#Port 22
Port 20682
default values are commented, if you uncomment new port it will override existing one.

#2 change ssh port in linux – restart sshd or ssh server – #

ssh for centos fedora redhat linux distributions.
sshd for ubuntu and debian both works fine.
service sshd reload
service sshd restart
systemctl restart ssh

Check SSH server listening newport or not

# netstat -tlpn| grep ssh
tcp 0 0 0.0.0.0:20682 0.0.0.0:* LISTEN 3529/sshd
tcp 0 0 0.0.0.0:1022 0.0.0.0:* LISTEN 1628/sshd
nano /etc/ufw/applications.d/ssh-server
remove port 22 from there.
22 port also listening

Login with New Port  – change ssh port in linux

How do I unblock port 22?
ufw allow 22

Block Port 22 Using UFW Firewall – change ssh port in linux

sudo ufw deny 22
root@-s-4vcpu-8gb-blr1-01:~# sudo ufw deny 22
WARN: Skipping ‘openssh-server‘: couldn’t process

Block Port 22 using  digitalocean firewall

go to networking >> firewall
Inbound Rules
Set the Firewall rules for incoming traffic. Only the specified ports will accept inbound connections. All other traffic will be blocked.
checkout digitalocean firewall
also know about digital ocean free credit

Check linux auth  syslogs get rid of ddos attacks

tail -f /var/log/auth.log

Apr 24 06:26:44 -s-4vcpu-8gb-blr1-01 sudo: root : TTY=pts/0 ; PWD=/root ; US ER=root ; COMMAND=/usr/sbin/ufw deny 22

Failed password for invalid user dong from 170.245.200.100 port 54354 ssh2
Apr 18 06:27:44 -s-4vcpu-8gb-blr1-01 sshd[19631]: Received disconnect from 170.245.200.100 port 54354:11: Bye Bye [preauth]
Apr 18 06:27:44 -s-4vcpu-8gb-blr1-01 sshd[19631]: Disconnected from invalid user dong 170.245.200.100 port 54354 [preauth]
Apr 18 06:27:58 -s-4vcpu-8gb-blr1-01 sshd[19633]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=80.169.112.191 user=root
Apr 18 06:28:00 -s-4vcpu-8gb-blr1-01 sshd[19633]: Failed password for root from 80.169.112.191 port 33064 ssh2
Apr 18 06:28:01 -s-4vcpu-8gb-blr1-01 sshd[19633]: Received disconnect from 80.169.112.191 port 33064:11: Bye Bye [preauth]
Apr 18 06:28:01 -s-4vcpu-8gb-blr1-01 sshd[19633]: Disconnected from authenticating user root 80.169.112.191 port 33064 [preauth]

//disable root login, password login, pamuse=no.

Summary on changing ssh linux port

Hope, you get clear understanding of  change of ssh port in linux, and the effects of changing linux ssh ports get rid bot traffic and strengthening linux server security you also want know about hardening linux security by tweaking sysctl. conf

Linux sysadmin tutorials linux system administrator

  • top 10 apt & apt-get commands (most used) apt vs apt-get
  • If-Else Statements in Shell Scripting
  • linux commands pdf (files & Directories, zip & unzip process, search etc)
  • Find Files with Specific Text on Linux grep find command
  • linux performance tuning inode limit file descriptors tco, kernel etc
  • Variables and Data Types in Shell Scripting
  • Top 10 most used Cat commands with examples (create, view, append files)
  • Ip tables / ufw / firewall d commands for block port ip rate limiting
  • Top 10 zip / tar commands to compress & extract files in linux
  • TOP 10 mv & cp commands in linux to move & copy files in Linux
  • Top 10 GREP Commands in linux to search files directory words strings
  • lsof netstat commands to know listening ports in linux 3 ways
  • Upgrade Ubuntu from 18.04 (19.10) to 20.04 LTS command line or gui server | desktop
  • 3 Ways (SCP, rsync, Sftp) linux server migration between two remote server apache nginx
  • linux system specs commands (CPU, Memory, Disk )speed, type. manufacture
  • linux sysctl command tweaks & hardening
  • linux security limits.conf deciding user limits process limits for nginx server
  • ulimit linux unlimited command unlimto set & know user limits open files file descriptor max user process etc.
  • red hat linux certification cost jobs salary syllabus courses fees
  • ufw firewall commads allow port enable disable ubuntu 20.04
  • ddos attack prevention
  • change ssh port in linux - avoid sshd ddos attacks
  • ping command
  • memcached install ubuntu wordpress
  • check linux version (lsb_release -a) ubuntu debian 32 or 64 bit
  • rsync command linux with examples comparison to scp
  • how to uninstall package in linux ubuntu rpm, yum apt-get
  • increase open file limit linux File descriptor ft nginx , mysql, lemp
  • remove repository ubuntu
  • htop commad memory details virtual vs shard vs resident
  • chown command in Linux with Examples
  • Kill PHP process
  • VIrtual Memory vs RSS Memory vs Shared memory in Linux
  • oom killer fixing it by configuration linux ubuntu
  • Install Lemp nginx mysql php fpm Stack on Debian 11 with repository
  • connect two remote servers linux command line
  • auto start after oom killer Mysql & php fpm nginx etc ubuntu wth systemd or cron job
  • load average Linux 1, 5, 15 min 2,4,8 cores explained
  • Control Structures in Shell Scripting
  • Shell Scripting Roadmap for Beginners to Advanced
  • awk commands with practical examples
  • Shell Scripting Tutorial for Beginners 🚀
  • find Command in Linux with Examples
  • sed Command in Linux with Examples (Beginner to Advanced)
  • Linux Text processing commands in with Examples
  • linux disk management commands
  • fdisk command in linux with examples
  • how to add a new disk in linux
  • Linux mount Command with Examples
  • fstab options with examples
  • Top 50 Shell Scripting Interview Questions and Answers
  • Linux Networking Interview Questions and Answers
  • Linux Networking Commands Cheat Sheet with Examples pdf
  • Netstat & SS Commands cheat sheet with examples Interview Questions
  • Nmap Cheat Sheet – Network Scanning & Security
  • Bash Brackets ([], (), {}, $( ), $(( ))) – Types, Uses & Examples

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy