This is rather strange story I want to share in case this originates from some kind of hack, so we can better identify signature of the attack.
I work as web developer, I run Ubuntu 20.04, I run strange things in docker on my machine, I have VSC with many development extensions of doubtful quality. I use ansible here and there Python venvs etc. I use ssh agent, my ssh key is password protected and I don't decrypt ssh key after login automatically.
Yesterday I was working as usual, switched off computer in the evening. Today I couldn't ssh to my remote machine with this message.
sign_and_send_pubkey: signing failed for RSA "/home/xxxxx/.ssh/id_rsa" from agent: agent refused operation
ubuntu@xxxxxxxx.xx: Permission denied (publickey).
After little fiddling I checked my private key and to my surprise it was destroyed.
$ cat ~/.ssh/id_rsa
-e
-e
is the content of the file, not happiest moments, but I have cold backup so I resumed work after a while.
But I can't sleep without knowing how this has happened. Lately I did not generate any new keys I did not manipulate files in .ssh/
manually.
The timestamp on the id_rsa
is yesterday mid-day during my work, also known_hosts
has the same timestamp, other files in .ssh/
have legitimate historical timestamps. Around the time I was sshing onto some old machines, so I can't see reason to touch known_hosts
file.
Can anyone think of a situation which would lead to overwriting id_rsa
with such non-sense as -e
? I'm paranoically thinking of a malicious code in some of the tools I use. Or of course my human error, but I'm usually quite vigilant. Thanks for your ideas.
Edit:
My
bash_history
is not complete, because of sub-optimal config of mybash
andtmux
, see https://askubuntu.com/questions/80371/bash-history-handling-with-multiple-terminals/80882. So tracking down specific command is unfortunately not posible.Based on answer I've discovered that VSCode creates lot of files starting with
-
, e.g.~/.config/Code/User/History/-707c1648
. Also I was lately having some performance issues with linters (running for couple seconds) and I've seen some temporary files being created next to the processed file. It lead me to hypothesis that maybe there is a clash in VSCode between git command and temporarily created file. This would need extra attention to track down.
history | grep -E 'id_rsa|-e'
shed any light? – Chris Davies Jul 26 '23 at 14:08ssh <name>
using names from my.ssh/config
– VasekCh Jul 26 '23 at 14:46history
there's nothing that comes to mind. – Panki Jul 26 '23 at 15:04-e
seems like it was a shell script gone haywire, then any sort of malicious behavior. – toppk Jul 26 '23 at 16:36