SSH config file - Run command before connection












0















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










share|improve this question

























  • 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


















0















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










share|improve this question

























  • 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
















0












0








0








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










share|improve this question
















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







linux ssh ssh-config






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 18:57









Rui F Ribeiro

39.5k1479132




39.5k1479132










asked Jan 4 at 11:29









KillouisKillouis

1




1













  • 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





















  • 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



















Have you considered aliases or functions?

– Jeff Schaller
Jan 4 at 11:57





Have you considered aliases or functions?

– Jeff Schaller
Jan 4 at 11:57




2




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





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





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





@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







@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












0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492458%2fssh-config-file-run-command-before-connection%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492458%2fssh-config-file-run-command-before-connection%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List directoties down one level, excluding some named directories and files

list processes belonging to a network namespace

list systemd RuntimeDirectory mounts