The file is an authorized_keys
file for SSH, often found in ~/.ssh/authorized_keys
. It has a number of fields, and the field you would like to remove is the first optional "options" field.
The second field is the "keytype" field, which will have one of the values ecdsa-sha2-nistp256
, ecdsa-sha2-nistp384
, ecdsa-sha2-nistp521
, ssh-ed25519
, ssh-dss
or ssh-rsa
, according to the sshd
manual.
We may use this fact to remove the options field:
sed -E 's/^.* (ecdsa-sha2-(nistp384|nistp521)|ssh-(ed25519|dss|rsa))/\1/' ~/.ssh/authorized_keys >~/.ssh/authorized_keys.new && mv ~/.ssh/authorized_keys.new ~/.ssh/authorized_keys && chmod go-rwx ~/.ssh/authorized_keys
Or, you may use sed -i ...
to change the file in-place if you know how this usually works on your Unix (the -i
flag works slightly differently in different implementations of sed
).
The sed
editing command s/^.* (ecdsa-sha2-(nistp384|nistp521)|ssh-(ed25519|dss|rsa))/\1/
will match the extended regular expression ^.* (ecdsa-sha2-(nistp384|nistp521)|ssh-(ed25519|dss|rsa))
and replace the matched text with the key type found on the line. The expression matches anything from the beginning of each line of input, up to, and including, one of the valid key types.
authorized_keys
which can have options as shown and normally does NOT have hostname/IP