I have the following running one liner to delete last injected ED key from last line of authorized keys folder of a remote host.
sed -i '${/^\(ssh-ed25519\) \(.*\) \([A-Za-z][A-Za-z]*\.[A-Za-z][A-Za-z]*@hpe\.com\)$/d;}' .ssh/authorized_keys
I do a couple of operations after creating ED key and injecting it into remote host. Then I want to clear up as tear down step. However when I tried to run it by connecting to remote host it failed. I tried the following things:
ssh -T 'sh -c "sed command here"' # too many single and double quotes, so I gave up
Then I tried removing T terminal and as well as "sh -c" command running part
ssh root@my_remote_host "sed -i '${/^\(ssh-ed25519\) \(.*\) \([A-Za-z][A-Za-z]*\.[A-Za-z][A-Za-z]*@hpe\.com\)$/d;}' .ssh/authorized_keys"
had this error:
sed: couldn't open temporary file .ssh/sedWC1YAQ: Read-only file system
I referred to this link but it also didn't help : Using SED in a ssh command on a remote node
I appreciate any help, and let me know if what I'm trying is a good way to apply.