SSH change port to 2021
Hi , ive installed ubuntu and doing some security stuff.
non root- done
ssh key - done
fail2ban - done
now im stuck at changing the port.
these are my steps.
sudo nano /etc/ssh/sshd_config , edited the port >
reboot server.ssh -p 2021 user@myip>
i receive error : ssh: connect to host myip port 2021: Connection refused
strange part is that i check the status it shows port 2021 active
user@localhost:~$ sudo netstat -tulpn |grep sshd>
tcp 0 0 0.0.0.0:2021 0.0.0.0:* LISTEN 1013/sshd: /usr/sbi
tcp6 0 0 :::2021 :::* LISTEN 1013/sshd: /usr/sbi>
so i open the firewall
sudo iptables -A INPUT -p tcp --dport 2021 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --dport 2021 -m state --state ESTABLISHED -j ACCEPT>
still cant go in. what am i doing wrong .?
5 Replies
Did you restart the firewall?
https://www.teclues.com/2020/03/start-stop-or-enable-disable-firewall-service-in-linux.html
Also, don't forget to close port 22.
-- sw
this is my ufw status
root@localhost:~# ufw status
Status: active
To Action From
-- ------ ----
2021 ALLOW Anywhere
2021 (v6) ALLOW Anywhere (v6)
Re-booting should have been sufficient. If it's not, then something else is not right… your sshd configuration perhaps. The config for the daemon is in /etc/ssh/sshd_config…NOT /etc/ssh/ssh_config…that's for the client.
-- sw
Hello there. Today, when I was trying to connect to my ubuntu VM, found that my connection was refused. I have changed the default ssh port in the past and haven't done any package upgrades. Finally I was able to connect on port 22 and found that I AM UNABLE to bind ssh daemon on any other port than 22. Seems like something is overwriting my config file.
Here are some details:
root@server:/etc/ssh# grep -i port sshd_config
Port and ListenAddress options are not used when sshd is socket-activated,
Port 2222
GatewayPorts no
root@server:/etc/ssh# systemctl restart ssh
root@server:/etc/ssh# systemctl restart ssh.socket
root@server:/etc/ssh# lsof -i :2222
root@server:/etc/ssh# ss -tnlp | grep ssh
LISTEN 0 4096 *:22 *:* users:(("sshd",pid=640809,fd=3),("systemd",pid=1,fd=47))
root@server:/etc/ssh# systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; disabled; preset: enabled)
Drop-In: /etc/systemd/system/ssh.service.d
└─00-socket.conf, linode.conf
Active: active (running) since Thu 2023-08-03 12:48:55 UTC; 22s ago
TriggeredBy: ● ssh.socket
Docs: man:sshd(8)
man:sshd_config(5)
Process: 640807 ExecStartPre=/usr/bin/ssh-keygen -A (code=exited, status=0/SUCCESS)
Process: 640808 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 640809 (sshd)
Tasks: 1 (limit: 4519)
Memory: 1.3M
CPU: 24ms
CGroup: /system.slice/ssh.service
└─640809 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Aug 03 12:48:55 server systemd[1]: Starting ssh.service - OpenBSD Secure Shell server…
Aug 03 12:48:55 server sshd[640809]: Server listening on :: port 22.
Aug 03 12:48:55 server systemd[1]: Started ssh.service - OpenBSD Secure Shell server.
root@server:/etc/ssh#