-1

Got myself into a sticky situation. I've got a bare metal server in a DC which is reasonably far in distance from me.

In any case, a few day ago I changed the SSH port from default to 6298 and now I need to change it back. Upon attempting to do so, it appears that I am no longer able to connect via SSH on any port number. Is there a way to reset SSH back to default? I don't really want to risk performing a system reboot as it could result in me not being able to access the server.

3
  • 4
    Log in from the (remote) console. Jan 16, 2016 at 0:17
  • 1
    What kind of connection do you have now (except hopefully the remote console)?
    – Sven
    Jan 16, 2016 at 0:17
  • do you have an ILO ? (e.g. management console) on the server ? (it's generally a dedicated network port from which you can connect remotely and access the server "console" from which you can login on the OS as root and change settings), if not, it will be hard.
    – olivierg
    Jan 22, 2023 at 20:02

4 Answers 4

1

Do you have KVM over IP remote console access via IPMI or DRAC, that will be giving you control.

In events where access such as SSH may be unavailable for some reason. Some places give the terminal window in the browser which securely proxies a serial console session to you server.

You still need to login to system using username and password via the TTY connected to the serial console.

0

When you say "I can not connect on ANY port number" - are you sure that you are trying the new ssh port ?

There are two possibilities

  1. ssh is not running
  2. ssh is running but on a port you are unaware off

To check we need to get into the server....

What other Services are running on the server ?

  1. SQL
  2. php
  3. sftp
  4. rdc (but not using ssh)

All of these may allow you to have a peek inside the server - to see if ssh is running - depending upon how you are secured these services will limit your access to the machine.

For the future you may wish to enable telnet for a short period prior to reconfiguring ssh - as it will grant you an alternative access mechanism.

1
  • 1
    instead of telnet you could just create a 2nd ssh configuration, start another ssh daemon with that configuration, check that you connect to that one as well, and only after that disable the "real" one. Jan 18, 2016 at 9:24
0

Unless you did something to turn off sshd entirely or otherwise ruined your sshd config, a reboot won't hurt you. On the opposite, it might be your only chance to properly restart sshd without having access to the console.

Once back online, do a portscan in case you made a typo entering the new port, then try to log back on.

0

Check below post on how to restore it, pretty much is reinstalling it.

a good practice is to always backup the original config file by using a command like this, for example:

cp /etc/ssh/sshd_config{,.original}

This will copy it to new file called sshd_config.original

Physically login to the device:

Restore default ssh server (sshd_config):

sudo apt-get install --reinstall openssh-server

Restore ssh client (ssh_config):

sudo apt-get install --reinstall openssh-client
4
  • Since the OP cannot connect to the server on any port, having he/she/them log in to make changes is not possible.
    – doneal24
    Jan 20, 2023 at 21:39
  • Logging in physically to the server is always an option. All hypervisor consoles also provide that. If you mess up the server that you can’t access it all. Just rebuild it then. Login to the server physically, fix the ssh, then remote in. It should that simple
    – MRK
    Jan 21, 2023 at 23:34
  • The OP said it is a bare metal server. What hypervisor are you referring to? Most server-class systems will have a bmc (or idrac, ilo, or equivalent) available but that would have had to have been wired up and configured.
    – doneal24
    Jan 22, 2023 at 2:26
  • you are right most servers come with idrac for example, and they are assigned a static ip for the from bios or can scan by nmap to find default idrac ip, and always the first admin login will be factory default. you spend thousands of dollars on server equipement and not setting this up for a disaster recovery worse that ssh then what's the point? All other hypervisors such as hyper-v, proxmox, or oracle vbox they provide direct access to the vm too. This really doesn't make sense to me. Most datacenters also provide direct access to your rack through their portal. even if not call up support.
    – MRK
    Jan 22, 2023 at 5:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .