Using SSH Key with Windows System: Headless Ubuntu Server via scp

Abstract: Configure SSH key authentication on Windows to enable passwordless scp transfers to a headless Ubuntu server.

Created: 2026-09-09 by
To securely transfer files between a Windows client and a headless Ubuntu server, you must configure SSH key authentication to eliminate password prompts during scp operations. This process involves generating an RSA or Ed25519 key pair on Windows using tools like OpenSSH or PuTTY, then copying the public key to the Ubuntu server's .ssh/authorized_keys file. Once configured, you can execute standard scp commands without manual intervention, ensuring automated and secure data synchronization for server management tasks.

Generating SSH Keys on Windows

The foundation of password-less authentication lies in the cryptographic key pair stored on your Windows machine. Modern versions of Windows 10 and 11 include the OpenSSH client by default, which simplifies this step significantly compared to older methods requiring third-party software. You should open PowerShell or Command Prompt as an administrator to ensure proper access to system directories, although standard user privileges are often sufficient for generating keys in the user profile folder. Run the following command to generate a new key pair. We recommend using the Ed25519 algorithm for its superior security and performance, though RSA remains widely compatible if your server has legacy constraints.
ssh-keygen -t ed25519 -C "[email protected]"
When prompted for a file location, press Enter to accept the default path (C:\Users\YourUsername\.ssh\id_ed25519). For enhanced security, you may choose to set a passphrase, but this will require entering it each time unless you use an SSH agent. If you prefer not to use a passphrase for fully automated scripts, simply press Enter twice when asked. The command outputs two files: the private key (which stays on Windows) and the public key (which goes to the server). Note that the public key file ends with .pub. If you are using an older version of Windows or a specific environment that lacks native OpenSSH, you might rely on PuTTYgen. In this case, generate the key in PuTTYgen and save both the private key (as a .ppk file) and the public key in OpenSSH format. However, migrating to native OpenSSH is strongly advised for consistency across Linux and Windows environments.

Transferring the Public Key to Ubuntu

The next critical step is placing your Windows public key into the correct directory on the headless Ubuntu server. Since the server is headless, you cannot use graphical interfaces; you must use command-line tools. The standard method is to use ssh-copy-id, which automates the appending of the key to the remote user's authorized keys file. Execute the following command from your Windows terminal, replacing username with your actual Ubuntu login name and server_ip with the server's IP address or hostname.
ssh-copy-id username@server_ip
This command attempts to log in using your existing password one last time to verify identity. Upon successful authentication, it creates the .ssh directory in the home folder if it does not exist, sets the correct permissions, and appends your public key to ~/.ssh/authorized_keys. If ssh-copy-id is unavailable due to a custom setup or restricted shell, you can manually copy the content of your .pub file and append it to the remote file using cat and >>:
cat ~/.ssh/id_ed25519.pub | ssh username@server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
After running this, verify that the key was added correctly by checking the contents of ~/.ssh/authorized_keys on the server via an SSH session. Ensure that the .ssh directory has permissions set to 700 and the authorized_keys file has permissions set to 600. Incorrect permissions are a common cause of authentication failures.

Configuring SSH for Seamless SCP Usage

With the key installed, you need to ensure that the SSH client on Windows prioritizes key-based authentication over password authentication. By default, SSH tries multiple authentication methods. To streamline this, you can create or edit the config file located at C:\Users\YourUsername\.ssh\config. Add the following entries to specify the key to use and disable password prompts for specific hosts.
Host server_alias
    HostName server_ip
    User username
    IdentityFile ~/.ssh/id_ed25519
    PubkeyAuthentication yes
    PasswordAuthentication no
Replace server_alias with a nickname for easy reference. This configuration tells the SSH client to always use the specified private key for connections to that host and to skip password challenges entirely. This prevents delays caused by failed password attempts and ensures that scp commands proceed immediately. You can test the connection by running ssh server_alias. If configured correctly, you should be logged in without any password prompt. Once verified, you can perform file transfers using scp. For example, to upload a file:
scp C:\path\to\localfile.txt server_alias:/remote/path/
And to download a file:
scp server_alias:/remote/path/remotefile.txt C:\path\to\destination\
For more complex network issues, such as connectivity errors, refer to Persistent SSH Error 'port 22: No route to host'. If you encounter issues with file dialogue windows in SSH sessions, see How to Open File Dialogue Window in SSH for Windows, PowerShell, and Ubuntu 20.04.

Troubleshooting Common Issues

Despite correct configuration, several factors can prevent key-based authentication from working. First, check the ownership and permissions on the server. The .ssh directory must be owned by the user, and group/world write permissions must be removed. Run chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys on the Ubuntu server. Second, ensure that the SSH daemon on Ubuntu is configured to allow public key authentication. Edit /etc/ssh/sshd_config and verify that PubkeyAuthentication yes is present and uncommented. Restart the SSH service with sudo systemctl restart sshd after making changes. Third, verify that the key type is supported. While Ed25519 and RSA are standard, some very old servers may require DSA or ECDSA, which are generally discouraged due to security weaknesses. If you suspect a protocol mismatch, check the SSH logs on the server at /var/log/auth.log for detailed error messages indicating why the authentication failed. Finally, if you are using a proxy or jump host, ensure that the IdentityFile path in your config is relative to the correct context. Sometimes, nested SSH sessions require forwarding the authentication agent using -A flag or configuring ForwardAgent yes in the local config.

Frequently Asked Questions

Why does scp still ask for a password even after adding the key?

This usually indicates incorrect file permissions on the server. Ensure that the .ssh directory is 700 and authorized_keys is 600. Also, verify that the key ownership matches the user account attempting the login.

Can I use the same SSH key for multiple Ubuntu servers?

Yes, you can copy the same public key to the authorized_keys file of multiple users or servers. This allows a single Windows machine to authenticate seamlessly across different systems without generating new keys for each.

What happens if my SSH private key is lost or stolen?

If the private key is compromised, anyone with it can access the associated servers. You must immediately remove the corresponding public key from all authorized_keys files on the servers. Then, generate a new key pair and distribute the new public key.

How do I handle SCP transfers through a firewall or NAT?

Ensure that port 22 is open on the Ubuntu server's firewall (e.g., UFW or iptables). If behind NAT, port forwarding must be configured on the router to direct incoming SSH traffic to the server's internal IP address. Check connectivity using telnet server_ip 22 from Windows.

Is it safe to store SSH keys without a passphrase?

Storing keys without a passphrase is convenient for automation but less secure. If the Windows machine is compromised, attackers can use the key directly. For better security, use a passphrase and an SSH agent, or restrict the key's usage with command restrictions in authorized_keys.

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