Ssh export-host-key fails in script but not in terminal

I am trying to run this command in a script:

/ip ssh export-host-key key-file-prefix="$sshHostKeyPrefix" passhprase="$sshHostKeyPassphrase";

The exact same command with the exact same values woks in the terminal, but in a script I get the following error:

Script Error: expected end of command (line 19 column 59)

This correlates to the end of the host key prefix flag.

At wits end with why this is failing. I have exported global variables and run exact same command without issue in terminal, it only fails in script.

  1. No RouterOS version AND hardware used specified (export do not matter this time).

  2. User right/policy?

  3. Only a part of a script, where is the rest? Where are the other 18 lines?

Don't kid us, it NOT works in the terminal.

  1. useless " and useless ;

It 100% is working in the terminal, though it must be hardcoded values. This garbage scripting language seems to be unable to interpolate the variable on that line.

No other part of the script is of note or an issue.

I like the ; at end, and the ""'s I added to try to make it interpolate.

I will just hardcode the values for this garbage OS.

e.g. /ip ssh export-host-key key-file-prefix="$sshHostKeyPrefix" passhprase="$sshHostKeyPassphrase"; doesn't work and /ip ssh export-host-key key-file-prefix="ssh/somepath" passphrase="somepassphrase"; does.

I don't believe you, you're still lying, I've already pointed out that you wrote it wrong, and you persist...

p–a–s–s–h–p–r-a-s–e

2 Likes

Any frill, is a frill.

Better to focus on writing the right commands and actually testing them...

Well, I am going to go take back all of this rage and eat my shoe now for being an idiot. Thank you rextended

1 Like

Thank you. I'm available, on what I know.

Now I am getting the same error with the typo corrected, but the command really does run on the CLI now. Can I share a screenshot

entire current script:

# :global sshHostKeyFile;
# :global sshHostKeyPassphrase;
# :global sshAdminPubKey;

:local sshHostKeyPrefix "rb5009_host";
# don't use $, ", or ? in passphrases
:local sshHostKeyPassphrase "password";
:local sshAdminPubKey "ssh/rb5009_admin_ed25519.pub";
# don't use $, ", or ? in passphrases
:local sshAdminPubKeyPassphrase "password";
/ip ssh set host-key-type=ed25519;
# only used for rsa, but set to max anyways
/ip ssh set host-key-size=8192;
/ip ssh set strong-crypto=yes;
:put "regenerate and backup host ssh keys in correct format";
/ip ssh regenerate-host-key;
/ip ssh export-host-key key-file-prefix=$sshHostKeyPrefix passphrase=$sshHostKeyPassphrase;
:put "importing admin key"
/user ssh-keys import public-key-file=$sshAdminPubKey user=username;

The first things I wrote still apply...
Don't make assumptions, paste the entire script... the RouterOS version and the hardware used...

1 Like

I edited post right after to include, it may not have updated for you yet.

RB5009UG+S+ on 7.20.6

This work for sure both on terminal and script, and I have tested that on 7.16.2.

I do not have any device at home now for test on 7.20.6

{
:local hkPref "rb5009_host"

# use \ for use $, ", or ? in passphrases
:local hkPass "pa\$\$word"

/ip ssh set host-key-type=ed25519

/ip ssh set host-key-size=8192

/ip ssh set strong-crypto=yes

/ip ssh regenerate-host-key

/ip ssh export-host-key key-file-prefix=$hkPref passphrase=$hkPass
}

I added that code, and removed my code, but I get the exact same error still.

Is there a reason removing a file and re-uploading a file would be a problem?

The only thing I can think right now is that I have kept referencing some wrong version, and get the same error because there are only 14 lines in your code, and I am getting the same line 19 error.

Steps: remove old script, upload new script, run. but getting old error

Aside from the fact that I obviously commented out the last line,
your version also works for me without errors,
both when running the script and when pasting into the terminal.

Reboot the device?

Ok, I think this is an issue with file system then.

I will reset config and cycle power.

It is weird that it is not referencing the file properly.

The passhprase type prbly is the version it keeps referencing.

Ya, that's what I am doing. I will need to remember this in future, because this was a weird issue.

Reset did it, thank you again for help

1 Like