0

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.

  • When I run the command `echo ssh root@my_remote_host "sed -i '${/^...' .ssh/authtorized_keys"` in bash I get a "bad substitution" error. The shell is taking the `${...}` as a parameter to expand. Try simply removing the double quotes: it's OK to send multiple arguments like `ssh host cmd arg ...` – glenn jackman May 07 '22 at 17:53
  • what is output of `ssh root@my_remote_host 'touch .ssh/test; rm .ssh/test'`? – jhnc May 07 '22 at 18:34
  • `touch: cannot touch '.ssh/test': Read-only file system rm: cannot remove '.ssh/test': No such file or directory` So I think now I have to think about removing the injected ED public key. Wont cause a harm I think if I leave it, next time I should not create another ED priv./pub key pair – GladiatorBobby May 07 '22 at 21:46

0 Answers0