How to Remove BOM Mark in SFTP Username when Using OpenSSH

Abstract: Resolves OpenSSH SFTP authentication failures caused by UTF-8 Byte Order Mark characters in the username configuration file.

Created: 2026-08-19 by

The Byte Order Mark (BOM) in an SFTP username is caused by invisible UTF-8 encoding characters, typically the EF BB BF sequence, embedded in your configuration files. To resolve this, you must edit your ~/.ssh/config or password store to remove these non-printing bytes, ensuring OpenSSH parses the username correctly without authentication failures.

Understanding the BOM Issue in SSH

When OpenSSH attempts to connect via SFTP, it reads credentials from configuration files such as ~/.ssh/config, ~/.ssh/known_hosts, or external helper programs like sshpass. If a file containing a username has been saved with a UTF-8 BOM, the client receives a string that starts with invisible control characters rather than the expected alphanumeric name. This results in errors like "Permission denied" or "Authentication failed," even if the password is correct. The server rejects the connection because the username presented includes hidden bytes that do not match any user account on the remote system. This issue often arises when text editors on Windows or macOS save files with specific encoding defaults, which are then transferred to a Linux environment using OpenSSH.

Detecting the BOM Character

Before attempting a fix, you should confirm that a BOM is present in your configuration file. You can use command-line tools to inspect the raw bytes of the file. The most effective method is using hexdump or od to view the hexadecimal representation of the first few lines. Run the following command on your ~/.ssh/config file:
hexdump -C ~/.ssh/config | head -n 5
If a BOM exists, the output will show the bytes ef bb bf at the very beginning of the file. These three bytes correspond to the UTF-8 encoded Byte Order Mark. If you see these bytes preceding your Host or User definitions, this confirms the root cause of your SFTP connection issues. Without removing these bytes, no amount of restarting the SSH agent or checking permissions will resolve the authentication error.

Using Vim to Inspect

Alternatively, you can open the file in Vim and check for the presence of a BOM by running:
:set bomb?
If Vim reports that the 'bomb' option is set, the file contains a BOM. This visual confirmation helps verify that the file encoding is the culprit before proceeding with removal steps.

Removing the BOM Using Command-Line Tools

The most reliable way to strip the BOM is using standard Unix utilities available on almost all Linux distributions. The sed command is particularly effective for this task because it can perform in-place editing while filtering out specific byte sequences. To remove the BOM from your SSH config file, execute the following command:
sed -i '1s/^\xef\xbb\xbf//' ~/.ssh/config
This command targets the first line (1s) of the file and substitutes the specific hex sequence of the BOM with nothing effectively deleting it. The -i flag ensures the changes are saved directly to the original file. After running this, verify the fix by running the hexdump command again; the ef bb bf sequence should no longer appear at the start of the file.

Alternative Method with Iconv

If sed is unavailable or behaves unexpectedly, you can use iconv to convert the file encoding. However, this requires creating a temporary file to avoid data loss during conversion:
iconv -f utf-8 -t utf-8 -c ~/.ssh/config > ~/.ssh/config.tmp && mv ~/.ssh/config.tmp ~/.ssh/config
The -c flag allows iconv to skip invalid characters, which may include the BOM depending on the implementation. Always back up your ~/.ssh/config file before performing mass conversions to prevent accidental corruption of your SSH settings.

Preventing Future BOM Injections

To ensure this issue does not recur, you should configure your text editor to save files without a BOM. Many modern editors allow you to set the default encoding to "UTF-8 without BOM." For example, in Visual Studio Code, you can change the setting "files.encoding": "utf8" instead of "utf8bom". In Notepad++, go to Settings > Preferences > New Document and select "UTF-8 without BOM" from the Encoding dropdown. Additionally, be cautious when transferring files between operating systems. If you edit configuration files on a Windows machine using a default text editor, they may automatically inject a BOM. It is best practice to perform all SSH configuration edits directly within the Linux environment using terminal-based editors like nano or vim, which do not add BOMs by default. For more information on managing SSH configurations securely, consider reviewing how to properly manage keys and access controls. See Fixing "Permission denied» with OpenSSH: Manually adding authorized_keys for related troubleshooting on authentication failures. Another useful resource is SSH User chroot Jail: Restricting SFTP Access to Specific Directory, which details further hardening measures for SFTP users.

Frequently Asked Questions

Why does my SFTP username work in some clients but not OpenSSH?

Some graphical SFTP clients may automatically strip whitespace or BOM characters before sending credentials, whereas OpenSSH strictly adheres to the raw content of the configuration file. This discrepancy means a file that works in FileZilla might fail in the command line due to hidden encoding artifacts.

Can I use sshpass with a BOM-containing username?

No, sshpass passes the username exactly as provided in the argument or script. If the variable holding the username contains a BOM, sshpass will transmit those invisible bytes, resulting in immediate authentication failure. You must sanitize the input string before passing it to sshpass.

How do I check if my known_hosts file has a BOM?

You can check ~/.ssh/known_hosts using the same hexdump command. While less common, if you generated this file on a different OS, it might contain a BOM. Removing it prevents potential parsing errors when SSH verifies host keys, though it rarely affects username authentication directly.

What happens if I accidentally delete part of the Host definition?

If the sed command removes too much content, your SSH configuration may become invalid, leading to connection timeouts or syntax errors. Always create a backup copy of ~/.ssh/config before running bulk edit commands, allowing you to restore the file if the substitution goes wrong.

Is the BOM issue specific to Linux systems?

The issue is primarily observed when Linux-based OpenSSH clients read files created or edited on Windows or macOS systems with specific default encodings. Linux text editors typically do not add BOMs unless explicitly configured to do so, making cross-platform file transfers the most common vector for this problem.

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