Help me to revert the file /root/.ssh/authorized_keys

Hi,

I copied the key of rsa.pub to authorized_keys using the below command

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

By mistake i have executed another command

view cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

so now additional keys are copied.so please help me how to revert the file ( /root/.ssh/authorized_keys ).

Ubuntu 16.04

Thank you

Can't you just edit the file and remove anything that shouldn't have been added?

Thanks for your suggestion
well,I tried to do.Bit confused which one to delete in the file once i opened it.If something necessary contents are deleted then unexpected behavior will be happend

---------- Post updated at 08:45 AM ---------- Previous update was at 08:08 AM ----------

Hi All,

I created this file in another user directory.I just don't care what i need to do with the wrong data copied

Maybe this will help???

# Move into the directory containing your files...
cd /root/.ssh

# Determine how many lines are in your corrupted file...
lines=$(wc -l < authorized_keys)

# Determine how many lines are in the file that was mistakenly added...
excess=$(wc -l < id_rsa.pub)

# Print directions...
printf 'authorized_keys contains %d lines.\n' $((lines))
printf 'id_rsa.pub contains %d lines.\n' $((excess))
printf 'Remove the last %d lines (starting with line #%d) from authorized_keys.\n' $((excess)) $((lines - excess + 1))