Score:0

ssh - private key file requires \n at the end of file or cause "Load key id_rsa invalid format"

vn flag
mon

Question

Has OpenSSH introduced a change that requires \n at the end of the private key file (id_rsa)? Previously I was on Ubuntu 18.04 and I believe id_rsa without \n at the end of the file was working. Now on Ubuntu 20.04, ssh does not work if id_rsa does not have \n at the end of the file.

$ diff id_rsa.bak.od id_rsa.od 
163,164c163,164
< 000a20       K   E   Y   -   -   -   -   -
< 000a29
---
> 000a20       K   E   Y   -   -   -   -   -  \n
> 000a2a

Without the \n, it causes the error.

$ ssh -i ~/.ssh/id_rsa ubuntu
Load key "/home/hadoop/.ssh/id_rsa": invalid format

Environment

$ ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
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"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
muru avatar
us flag
Having a newline at the end of each line *is* what makes it a line (and a file a text file) [by definition](https://unix.stackexchange.com/a/446241/70524). So, when you say "I believe id_rsa without \n at the end of the file was working," I strongly recommend you verify that using a VM or a container.
uz flag
Jos
FWIW some of my private key files go back to 2017, and all of them have a `\n` at the end.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.