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
  • Have you considered aliases or functions? – Jeff Schaller Jan 4 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 at 12:34
  • What command in particular are you trying to run? – Damian T. Jan 4 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 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 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.