How to Change the SSHD Port and Enable Password Authentication on Ubuntu 24.04

In this guide we will look into how to change port for sshd in ubuntu 24.04. SSHD also called as SSH daemon is a server side application for SSH protocol. It listens for the incoming SSH connections and is responsible for authentication, encryption, and session management for these connections. The service is started when the system boots and wait for the clients connections while running in the background.

You might have come to the issue saying that sshd service is not present in ubuntu 24.04 while changing ssh listening port.

Failed to restart sshd.service: Unit sshd.service not found.

Key features and Configurations of sshd (ssh daemon)

Before diving into how to enable the password authentication and change ssh port in ubuntu 24.04. Let us have a look at the key functions and the configurations that can be done in case of sshd.

Key Functions:

  1. Listening for Connections: sshd listens on a specific port (default is port 22) for incoming SSH connections.
  2. Authentication: Upon receiving a connection request, sshd performs authentication using the methods configured (e.g., password, public key, GSSAPI).
  3. Session Management: After successful authentication, sshd sets up the user session, including user environment, user permissions, and the command shell.
  4. Logging and Monitoring: sshd logs connection attempts, successful logins, and other relevant events for security monitoring.

Configuration:

sshd is configured using the sshd_config file generally in case of other Ubuntu OS, In case of Ubuntu 24.04 the file is typically located at /etc/ssh/sshd_config.d/ directory. Key configuration options include:

  • Port: This setting determines the port that sshd listens on for incoming connections. By default, it’s set to port 22.
  • PermitRootLogin: This option controls whether or not the root user is allowed to log in via SSH. It’s generally recommended to disable root login for security reasons.
  • PasswordAuthentication: This setting enables or disables the ability to log in using a password. Disabling this can help enhance security by relying solely on key-based authentication.
  • PubkeyAuthentication: This option allows you to enable or disable public key authentication, which is generally more secure than password-based logins.
  • AllowUsers/AllowGroups: These directives let you specify which users or groups are permitted to log in via SSH, providing an additional layer of access control.

How to change port for sshd in ubuntu 24.04

Below is the step by step guide to change port for sshd in ubuntu 24.04.

Step 1: Login to the ubuntu 24.04 server

After login to the server you will be needing the root access for the server to modify the sshd_config file.

You can check the version of the OS using below command:

cat /etc/os-release
root@ip-172-31-88-206:~# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

Step 2: Change port for sshd

To enable the password authentication in ubuntu 24.04 we need to navigate to the /etc/ssh/sshd_config.d directory. You can use this command:

cd /etc/ssh/sshd_config.d/

In this directory you will find a configuration file. Edit the file using and editor like vim or nano.

nano 60-cloudimg-settings.conf

You can use the file name as per the file present in your configuration directory. You need to add a line in the file like this:

Port 2222

Step 3: Restart the server

For the changes to make place you need to restart the server. You can reboot the server using below command.

reboot

Step 4: Connect to your server using password

Now you can use any ssh client to connect to your server using username and password. You can also use the blow command from your terminal to connect to your server.

ssh username@ip-address -p port

Username will be the username you set for your server and the IP address will the your server IP address.

Step 5: Check the port for ssh using ss command

You can use ss command to confirm the the port for sshd is changed for the server.

ss -tulpn

Thanks for reading the guide. Hope by following this guide you were able change port for sshd in ubuntu 24.04. For more Linux related content do visit our website simplealltech.com.

How to Enable password authentication for sshd in ubuntu 24.04

In this guide we will look into how to enable the password authentication in case of ubuntu 24.04. Below is the step by step guide to enable the sshd password authentication.

Step 1: Login to the ubuntu 24.04 server

After login to the server you will be needing the root access for the server to modify the sshd_config file.

You can check the version of the OS using below command:

cat /etc/os-release
root@ip-172-31-88-206:~# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

Step 2: Enable the password authentication

To enable the password authentication in ubuntu 24.04 we need to navigate to the /etc/ssh/sshd_config.d directory. You can use this command:

cd /etc/ssh/sshd_config.d/

In this directory you will find a configuration file. Edit the file using and editor like vim or nano.

nano 60-cloudimg-settings.conf

You can use the file name as per the file present in your configuration directory.

In this file you have to enable this:

PasswordAuthentication yes

Step 3: Restart the ssh service

Now you need to restart the SSH service by using this command:

systemctl restart ssh.service

Step 4: Connect to your server using password

Now you can use any ssh client to connect to your server using username and password. You can also use the blow command from your terminal to connect to your server.

ssh username@ip-address -p port

Username will be the username you set for your server and the IP address will the your server IP address.

Thanks for reading the guide. Hope by following this guide you were able to enable password authentication for sshd in ubuntu 24.04. For more Linux related content do visit our website simplealltech.com. How to change the listening port for sshd you can also refer to the blog on our website https://simplealltech.com/how-to-change-port-for-sshd-in-ubuntu-24-04/.

Leave a Comment