(Nerd) How to: Reconfigure SSH listening port on Ubuntu 9.10
Posted on December 23, 2009
1) Make sure that you have have ssh installed on your system.
sudo apt-get install openssh-server openssh-client |
2) Open the sshd_config file using VI
sudo vi /etc/ssh/sshd_config |
3) Here is the file in its entirety that was created by the installation process
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | # Package generated configuration file # See the sshd(8) manpage for details # What ports, IPs and protocols we listen for Port 22 # Use these options to restrict which interfaces/protocols sshd will bind to #ListenAddress :: #ListenAddress 0.0.0.0 Protocol 2 # HostKeys for protocol version 2 HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key #Privilege Separation is turned on for security UsePrivilegeSeparation yes # Lifetime and size of ephemeral version 1 server key KeyRegenerationInterval 3600 ServerKeyBits 768 # Logging SyslogFacility AUTH LogLevel INFO # Authentication: LoginGraceTime 120 PermitRootLogin yes StrictModes yes RSAAuthentication yes PubkeyAuthentication yes #AuthorizedKeysFile %h/.ssh/authorized_keys # Don't read the user's ~/.rhosts and ~/.shosts files IgnoreRhosts yes # For this to work you will also need host keys in /etc/ssh_known_hosts RhostsRSAAuthentication no # similar for protocol version 2 HostbasedAuthentication no # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication #IgnoreUserKnownHosts yes # To enable empty passwords, change to yes (NOT RECOMMENDED) PermitEmptyPasswords no # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication no # Change to no to disable tunnelled clear text passwords #PasswordAuthentication yes # Kerberos options #KerberosAuthentication no #KerberosGetAFSToken no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes X11Forwarding yes X11DisplayOffset 10 PrintMotd no PrintLastLog yes TCPKeepAlive yes #UseLogin no #MaxStartups 10:30:60 #Banner /etc/issue.net # Allow client to pass locale environment variables AcceptEnv LANG LC_* Subsystem sftp /usr/lib/openssh/sftp-server UsePAM yes |
4) But we are mainly concerned with this part right here
1 2 3 4 5 6 7 | # Package generated configuration file # See the sshd(8) manpage for details # What ports, IPs and protocols we listen for Port 22 ... |
5) Change the default port that is currently 22, to a non standard port. I changed mine to 22999
1 2 3 4 5 6 7 | # Package generated configuration file # See the sshd(8) manpage for details # What ports, IPs and protocols we listen for Port 22999 ... |
6) Write/Quite so that you can save the changes to the file.
7) Now, all we have to do is restart the ssh daemon and it will listen from the new port.
sudo /etc/init.d/ssh restart |
8 ) Finally, from another linux (or whatever OS you prefer) box, use the SSH client and login to your newly reconfigured server. Make sure to change the port using the ‘-p’ flag.
Example: ssh YOUR_USERNAME@IP_ADDRESS_OF_SERVER -p 22999
ssh jaredfolkins@192.168.1.107 -p 22999 |

Leave A Comment