2

i cannot run a command before connect with ssh to remote server using ~/.ssh/config file.

I have tried with options "ProxyCommand" and "LocalCommand" but it doesn't work.

  • ProxyCommand: seems it run the command, but after that doesn't ask me the password of ssh connection
  • LocalCommand: run the command only if the connection successful
11
  • Have you considered aliases or functions?
    – Jeff Schaller
    Jan 4, 2019 at 11:57
  • 2
    Theorectically it could be done with ProxyCommand and passing a scriptname that contains what you want to be executed, but you need to ensure that the script ends with setting up a connection to the remote host, fulfilling the "proxy" part. E.g. /usr/bin/nc %h %p
    – wurtel
    Jan 4, 2019 at 12:34
  • What command in particular are you trying to run?
    – Damian T.
    Jan 4, 2019 at 14:30
  • @JeffSchaller Thanks for your answare. Yes, before i was using aliases, but config file of ssh is more portable and smart than aliases.
    – Killouis
    Jan 4, 2019 at 15:01
  • @wurtel Thanks for your answare. Can i put my command and on success execute "nc" without log? E.g. /bin/echo hello > /tmp/test && /usr/bin/nc %h %p > /dev/null 2>&1
    – Killouis
    Jan 4, 2019 at 15:04

1 Answer 1

2

See these answers: https://unix.stackexchange.com/a/44343 (using ProxyCommand) and https://askubuntu.com/a/1268036 (using Match host ... exec)

1
  • I solved with the Match host! Thank you @silas-s-brown :)
    – Killouis
    Dec 26, 2020 at 18:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .