I want to delete/comment one of the ssh key in my remote server . current node = node1 remote node = node2 In node one I have pub file and the content of the pub file need to delete from remote node /home/cloud-user/.ssh/authorized_keys . Tried with sed command but its not worked. Below Command tried in my setup .
test1
pub file name = cluster.pub (content of pub includes space )
key=$(cat /opt/key/cluster.pub)
ssh -i key.pem node2 "sed -i 's/$key/#$key/g' /home/cloud-user/.ssh/authorized_keys"
error msg
sed: -e expression #1, char 0: no previous regular expression
test2
copied the cluster.pub into node2:/tmp/
ssh -i key.pem node2 "key= cat '/tmp/cluster_login.pub' ;sed -e 's/${key}/#${key}/' /home/cloud-user/.ssh/authorized_keys"
error msg
sed: -e expression #1, char 230: unknown option to `s'
Looks like while running in remote shell sed command is executing in a different method .