I got response from Cisco Tech support and there are a few things not correctly described in the manual.
First, ASR router supports key size 1024 bit or smaller contrary to its manual(supporting up to 2048 bit key).
Second, only the key part of SSH public key must be 'de'coded w/ base64 en/decoding program.
SSH Key Generation
ssh-keygen -b 1024 -t rsa -f myrouter_sshkey
This will generate myrouter_sshkey
and myrouter_sshkey.pub
. When you look into the public key file, it looks like followings:
ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAAAgQDR/ggtknqBZ50pIAyzw0E93wfu2EsGLnft/uF6N4ov6Dsp1H7yoC5ssE+yOcrWHeDEQnD0BsNCLZPW+ye7jjYeE+CUrOINpi04PtD+zx95knpAFnREMV7w8fJ9c7/SMb2L4Jk6KlmTcqtM+lUgrxEnCD7Z1kpCUzkP+0D0N/RG2Q==
[email protected]
We only need the second part of the public key file separated by space for base64 decoding.
'de'code SSH public key with base64.
cut -d" " -f2 myrouter_sshkey.pub | base64 -d > myrouter_sshkey.pub.b64
This generated file is binary format and can be imported to ASR router.
Note that if you're using MAC, use -D option instead.
Upload 'de'coded public key to the router.
RP/0/RSP0/CPU0:ASR9K#copy ftp:myrouter_sshkey.pub.b64 harddisk:/
I used ftp but you can use tftp or else.
import public key to a router user.
RP/0/RSP0/CPU0:ASR9K#admin
RP/0/RSP0/CPU0:ASR9K(admin)#crypto key import authentication rsa username admin
Verify key import
RP/0/RSP0/CPU0:ASR9K(admin)#sh crypto key authentication rsa all
Key label: admin
Type : RSA public key authentication
Size : 1024
Imported : 18:39:54 UTC Thu Jul 03 2014
Data :
{{intentionally removed}}
Login test
ssh -oIdentitiesOnly=yes -i myrouter_sshkey ${myrouter}
Note that if you have more than one ssh keys, -oIdentitiesOnly=yes
must be given or your connection will fail. SSH tries every keys sequentially until one of the keys is accepted or finally falls back to password authentication if applicable. SSH server may allow this multiple key trials even if the first key trial fails. Unfortunately ASR router seems not to allow this. If the first tried key fails, it disconnect the session. To explicitly specify the key you use, give -oIdentitiesOnly=yes
option to ssh.