Results 1 to 10 of 10

Thread: SSH port changes as soon as SSH is updated.

  1. #1
    Join Date
    Oct 2023
    Beans
    24

    SSH port changes as soon as SSH is updated.

    hello,
    every time I update SSH with an apt upgrade,
    my SSH port is rolled back to 22.

    I use a custom port and in ubuntu you must modifiy the
    /lib/systemd/system/ssh.socket
    file to use a custom port.

    This works well but every time SSH is updated, apt restores that file to port 22.

    Is there a way to change the SSH port forever?

  2. #2
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: SSH port changes as soon as SSH is updated.

    For the server, you should modify /etc/ssh/sshd_config and change its "Ports" designation.

    For the client, apply the same change to /etc/ssh/ssh_config or use "ssh -p 12345 server_name".
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    Join Date
    Oct 2023
    Beans
    24

    Re: SSH port changes as soon as SSH is updated.

    Quote Originally Posted by SeijiSensei View Post
    For the server, you should modify /etc/ssh/sshd_config and change its "Ports" designation.
    that file only does not change the SSH port in Ubuntu 23.10

  4. #4
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: SSH port changes as soon as SSH is updated.

    As I said, you also need to change /etc/ssh/ssh_config if you want the client to default to a different port.

    These have been the standard configuration files for ssh for years now. I doubt it doesn't work in 23.10, but I never use anything other than LTS versions.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #5
    Join Date
    Oct 2023
    Beans
    24

    Re: SSH port changes as soon as SSH is updated.

    Quote Originally Posted by SeijiSensei View Post
    As I said, you also need to change /etc/ssh/ssh_config if you want the client to default to a different port.

    These have been the standard configuration files for ssh for years now. I doubt it doesn't work in 23.10, but I never use anything other than LTS versions.
    that's what I have done but as said to change the SSH port on 23.10 you need to edit both
    /etc/ssh/ssh_config
    and
    /lib/systemd/system/ssh.socket

    but
    /lib/systemd/system/ssh.socket

    is automatically changed by apt upgrade every time there is an update.

  6. #6
    Join Date
    Aug 2016
    Location
    Wandering
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: SSH port changes as soon as SSH is updated.

    Quote Originally Posted by sblantipodi View Post
    that file only does not change the SSH port in Ubuntu 23.10
    SSHd now uses socket-based activation (Ubuntu 22.10 and later)
    Some info that might help: https://discourse.ubuntu.com/t/sshd-...nd-later/30189
    With realization of one's own potential and self-confidence in one's ability, one can build a better world.
    Dalai Lama>>
    Code Tags | System-info | Forum Guide lines | Arch Linux, Debian Unstable, FreeBSD

  7. #7
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: SSH port changes as soon as SSH is updated.

    After reading that document, I intend to run
    Code:
    sudo rm /etc/systemd/system/ssh.service.d/00-socket.conf
    sudo systemctl disable --now ssh.socket
    sudp systemctl enable --now ssh.service
    sudo systemctl daemon-reload
    sudo systemctl restart ssh
    on every future installation of Ubuntu.

    All of this is to save a few megabytes of storage? Change the method of configuring sshd that we've all used for decades for that? Who are these developers? Do they talk to real sysadmins in the world?
    Last edited by SeijiSensei; January 8th, 2024 at 07:05 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  8. #8
    Join Date
    Oct 2023
    Beans
    24

    Re: SSH port changes as soon as SSH is updated.

    Quote Originally Posted by SeijiSensei View Post
    After reading that document, I intend to run
    Code:
    sudo systemctl disable --now ssh.socket
    sudo systemctl enable --now ssh.service
    on every future installation of Ubuntu.
    does this two commands supposed to fix my issue?
    thanks you very much for the answer...

    the link above does not open here

  9. #9
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: SSH port changes as soon as SSH is updated.

    Follow the more extensive set of commands I just posted.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  10. #10
    Join Date
    Oct 2023
    Beans
    24

    Re: SSH port changes as soon as SSH is updated.

    ok thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •