ssh 192.168.88.1 "/file print file=mykey; file set mykey contents=\"`cat ~/.ssh/id_rsa.pub`\";/user ssh-keys import public-key-file=mykey.txt;/ip ssh set always-allow-password-login=yes"
Now you won’t need to enter your router password to log in to RouterOS with SSH. Hope it helps! It does the same as ssh-copy-id Linux command that nowadays works even on Windows and OSX.
Another tip is you can ssh into Routeros with username+ct@router instead of just username@router, then login will be even quicker. Add “user myname+ct” under “host router” section in /etc/ssh_config to make it the default. Also
/print detail
prints all the infos you need, that print hides because of its silly formatting.
thank you a bunch ! I couldn’t believe that ss-copy-id wasn’t support even in routerOS 7.1.1. I was getting this error after entering my router’s password during ssh-copy-id:
@olivier2831 kujo's script works for me on 7.21.5 when run step by step, RSA and Ed25519 both. That error means import got something other than a key. Usually /file set didn't land and file still holds /file print output. Check with /file print detail where name=mykey.txt.