Notable: Connecting to an EC2 instance using SSH with password authentication - Ubuntu 22.04

Abstract: Enable password authentication for SSH on Ubuntu 22.04 EC2 instances by configuring the user account and sshd settings.

Created: 2026-09-07 by
You can connect to an Ubuntu 22.04 EC2 instance using SSH with password authentication by creating a new user, setting a password, and configuring the SSH daemon to allow this method. This approach bypasses the default key-based security model, allowing direct credential entry via standard SSH clients like PuTTY or OpenSSH.

Creating the User Account

The first step involves establishing a dedicated user account on the EC2 instance. While the root user exists, it is best practice to create a separate administrative user for daily operations. You can achieve this by connecting to the instance using your existing key pair or the AWS Systems Manager Session Manager. Once you have shell access, execute the useradd command followed by the desired username. For example, running sudo useradd -m demo117 creates the user and automatically generates a home directory. The -m flag ensures that the necessary directory structure is initialized within /home. After the user is created, you must assign a password. Use the passwd command followed by the username. Running sudo passwd demo117 prompts you to enter and confirm a strong password. This password will be used for subsequent SSH login attempts. It is crucial to choose a complex password that meets security standards, as password authentication is generally less secure than key-based methods.

Configuring SSH Daemon Settings

By default, Ubuntu 22.04 instances disable password authentication for security reasons. To enable it, you must modify the SSH daemon configuration file. Open the file located at /etc/ssh/sshd_config using a text editor such as nano or vim. Search for the directive labeled PasswordAuthentication. In many default configurations, this line may be commented out with a hash symbol (#) or set to no. Change the value to yes. If the line is commented out, remove the leading hash symbol to uncomment it. Ensure the line reads exactly as PasswordAuthentication yes. Additionally, verify that the PermitRootLogin directive is set appropriately. For enhanced security, it is recommended to keep root login disabled (PermitRootLogin no) and use your new user account instead. After making these changes, save the file and exit the editor. To apply the changes, restart the SSH service. Run the command sudo systemctl restart sshd. This action reloads the configuration without requiring a full server reboot. If the service fails to restart, check the logs for syntax errors in the configuration file.

Connecting via SSH

With the user created and the SSH daemon configured, you can now initiate a connection from your local machine. Open your terminal or SSH client and use the standard SSH syntax. The command structure is ssh username@public_ip_address. Replace username with the name you created, such as demo117, and public_ip_address with the public IPv4 address of your EC2 instance. For example:
ssh [email protected]
Your client will prompt you for the password you set earlier. Enter the password carefully; note that characters will not be displayed on the screen for security purposes. Press Enter after typing the password. If the credentials are correct and the network security group allows inbound traffic on port 22, you will gain access to the remote shell. If you encounter connection issues, ensure that the EC2 security group associated with the instance has an inbound rule allowing TCP traffic on port 22 from your IP address. Without this rule, the connection attempt will time out regardless of the SSH configuration. You can also refer to Configuring a New User on AWS EC2 with SSH (Ubuntu) for additional context on user management best practices.

Troubleshooting Common Issues

Several factors can prevent successful password authentication. First, verify that the SSH service is actually running on the instance. Use sudo systemctl status sshd to check its state. If it is inactive, start it with sudo systemctl start sshd. Second, check the SSH logs for detailed error messages. The log file is typically located at /var/log/auth.log. Look for entries related to sshd around the time of your connection attempt. Common errors include "Permission denied" if the password is incorrect or "Connection refused" if the port is blocked. Another potential issue is the SSH client configuration on your local machine. Some clients or system-wide configurations may prioritize key-based authentication over passwords. You can force password authentication by adding the -o PreferredAuthentications=password flag to your SSH command. This tells the client to only attempt password login, ignoring any private keys present in your .ssh directory. For more insights on securing your SSH sessions, consider reviewing Avoiding Google Authenticator Re-Authentication in Existing SSH Sessions on EC2.

Frequently Asked Questions

Is password authentication secure for EC2 instances?

Password authentication is generally considered less secure than key-based authentication because passwords can be guessed or brute-forced. AWS recommends using key pairs for all new instances to enhance security. However, password auth can be useful for temporary access or specific legacy systems.

How do I disable password authentication again?

To disable password authentication, edit the /etc/ssh/sshd_config file and change PasswordAuthentication back to no. Restart the SSH service using sudo systemctl restart sshd for the changes to take effect.

What if I forget the password I set?

If you forget the password, you cannot recover it directly. You must reset it by accessing the instance through the AWS Console's EC2 Instance Connect feature or by stopping the instance, detaching the root volume, attaching it to another instance, and modifying the password file manually.

Can I use password authentication with root user?

While technically possible, enabling password authentication for the root user is strongly discouraged due to high security risks. It is safer to create a regular user with sudo privileges and use password authentication for that user instead.

Why does my SSH connection still fail after changing settings?

Ensure that the security group attached to your EC2 instance allows inbound traffic on port 22 from your current IP address. Additionally, verify that the SSH service is running and that there are no typos in the configuration file that might prevent the service from restarting properly.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More