DEV Community

Alex Antsiferov
Alex Antsiferov

Posted on • Updated on

unexpected EF BB BF

Got this little funny hiccup while setting up a remote Ubuntu server.

As soon as I created the user account, I decided to add my public key to authorized_keys so I could log in without password. Since Windows doesn't have ssh-copy-id, I ran this nifty command in PowerShell:

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {SERVER} "cat >> .ssh/authorized_keys"
Enter fullscreen mode Exit fullscreen mode

My public key was copied to authorized_keys, perfect! But on the next login I still got the password prompt. What the..?

I ran ssh with -vv key to get more info, rechecked everything twice, and finally noticed that the newly added key had some extra characters.
And no, these were not CRLF. This time it was a mysterious EF BB BF sequence also known as BOM:

> 00000000: efbb bf73 7368 2d72 7361 2041 4141 4142  ...ssh-rsa AAAAB
Enter fullscreen mode Exit fullscreen mode

After I removed them, ssh recognized my key and everything worked as expected. Don't I just love this stuff!

A couple more useful commands:

xxd myfile # hex dump myfile
diff -y <(xxd myfile1.bin) <(xxd myfile2.bin) # compare binaries
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
redeyed profile image
Vadym Stupakov • Edited

I faced same problem!
I found the way how to solve it:
remove all non ascii characters in ~/.ssh/authorized_keys
LANG=C sed -i 's/[\d128-\d255]//g' ~/.ssh/authorized_keys

so the final commad for ssh-copy-id under windows is:
type ~/.ssh/id_rsa.pub | ssh USER@HOST "mkdir -p ~/.ssh && LANG=C sed 's/[\d128-\d255]//g' >> ~/.ssh/authorized_keys"