Instead of using sshpass
, you can also add your public key:
ssh 192.168.88.1 "/file print file=key; file set key contents=\"`cat ~/.ssh/id_rsa.pub`\";/user ssh-keys import public-key-file=key.txt;/ip ssh set always-allow-password-login=yes"
Then you can just ssh without having to use sshpass. If you're using ssh mostly, then you can disable colorisation by changing your username to username+ct
in your /etc/ssh/ssh_config
for your mikrotik hosts, or just ssh username+ct@router
.
@DamianK's answer becomes:
where="<path to your mikrotik config.txt>";
len=`cat $where | wc -l`;
config=`for (( c=1; c<=$len; c++ )) do line=\`sed -n "$c""p" $where\`; echo $line; done`;
ssh x.x.x.x $config
Another nifty thing you can do is to tell ssh to keep the connections open for, say, 600
seconds - then you don't get the login delay of running ssh
multiple times, so you can use @esstorm's answer. Just put this in your /etc/ssh/ssh_config
:
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h-%p
ControlPersist 600
The only snag is that if the connection times out, connecting will hang if you reconnect within that timeout. You can of course manually delete the socket, which you can find with find .ssh/sock*
@esstorm's answer becomes:
while read l;do
ssh y@x.x.x.x ip proxy access add dst-host ="$l" action = deny comment ='list'
done < list.txt