Some companies change the port address (number) of a service from one to another; for example, some companies change the address of SSH port from 22 to something else.

Is changing a service's port from one to another done through a shell directly? For example, is there a Bash built-in to do so, or is it done solely from the file tree of each application (such as SSH and alike)?


The precise answer to the question as asked, is no, the shell has nothing to do with the port numbers used. The shell is only an interface between entities, such as you (the user), and the commands/applications/services provided by the system.

Services typically provide different means to modify which port they use:

  1. A default, as (usually) defined in the service's documentation.
  2. A dedicated configuration file somewhere.
  3. A command line option or argument (which may override any of the above).
  4. Some other means, such a web interface to it's configuration and operation.

Most services, including ssh, offer the means to change the port used by editing their configuration file and restarting the service.

In the case of ssh, it would be in /etc/ssh/sshd_config.

That said, there's nothing stopping you from writing your own script to perform such changes. sed and awk offer an easy means to manipulate text files from within a script.

  • 1
    Hello. Thanks. If I figured out your answer correctly ; in general, shells don't suffice any tools to change a service's port from one to another --- it can be done indirectly via shells, but never directly. Is that correct? Jun 27 at 9:05
  • 1
    @puertoportopoio A shell is (mostly) a way to run other programs ("commands"), it doesn't really do much itself. Which port a service listens on is (generally) controlled by the server program, which isn't usually run by a shell, but by some background system component. Therefore, the connection between shells and which ports services listen on is very very indirect. That said, there are always exceptions; some shells are capable of listening for network connections, and I suppose you could write a server program in such a shell... but I don't know why you'd want to. Jun 27 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.