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

Tags
ubuntu, ubuntu 16.04

 
Thread Tools Search this Thread
# 1  
Old 10-07-2017
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
Code:
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

By mistake i have executed another command
Code:
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


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
Help me to revert the file /root/.ssh/authorized_keys-ccat_screenshot-png

Last edited by RudiC; 10-09-2017 at 04:49 AM.. Reason: Added CODE tags.
# 2  
Old 10-07-2017
Can't you just edit the file and remove anything that shouldn't have been added?
# 3  
Old 10-08-2017
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
# 4  
Old 10-08-2017
Maybe this will help???
Code:
# 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))


|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Appending authorized_keys on multiple servers using ssh Grueben Shell Programming and Scripting 0 03-17-2015 07:16 AM
Auditors want more security with root to root access via ssh keys dvbell SuSE 6 07-12-2013 10:33 AM
Passwordless ssh for root sai_2507 Solaris 6 01-06-2013 12:10 AM
ssh as root Junaid Subhani Solaris 4 10-31-2012 04:17 AM
Is it possible to revert a file after overwriting it ? noPermissions Linux 1 12-02-2011 12:15 PM
Solaris 8: root can't ssh to other systems. aixlover Solaris 7 10-14-2011 05:20 PM
SSH w/ command in authorized_keys apparently needs pty KenJackson Shell Programming and Scripting 12 07-11-2011 09:44 PM
passwordless ssh for non-root user??? rs6000er AIX 9 11-11-2010 04:06 PM
Can't SSH as root anymore! cquarry UNIX for Dummies Questions & Answers 3 11-14-2009 06:37 AM
Running script through SSH as root irinotecan Security 4 03-30-2009 06:57 PM
Unable to telnet (non-ssh) as root anilgurwara SuSE 2 03-20-2009 04:47 PM
Passwordless root authentication via SSH sphericon AIX 3 11-20-2007 09:58 AM
monitoring SSH authorized_keys prvnrk UNIX for Advanced & Expert Users 1 07-23-2007 11:16 AM
monitoring SSH authorized_keys prvnrk Shell Programming and Scripting 0 07-19-2007 12:10 PM
deny ssh from root - how to? theDirtiest UNIX for Dummies Questions & Answers 3 11-17-2001 12:33 PM