Running commands over ssh with Java

后端 未结 6 533
北荒
北荒 2020-12-05 16:06

Scenerio: I\'d like to run commands on remote machines from a Java program over ssh (I am using OpenSSH on my development machine). I\'d also like to make the ssh connecti

6条回答
  •  遥遥无期
    2020-12-05 17:09

    Echoing others' suggestion to use a Java SSH library. But wanted to comment on Cohen's response. Sending your password over the command line when establishing the connection is insecure and also not permitted by many sshd servers (based on configuration).

    You might want to look into setting up keys for this, so you can perform ssh commands between the machines without a password.

    Basic steps - use openssh to create a keypair (I've done RSA but I know there's a better method now) - create a .ssh directory in your home folder on the SOURCE machine - create a .ssh directory in your home folder on the TARGET machine - keep your private key in your source machine's .ssh folder - copy your public key into a file called authorized_keys in the target's .ssh folder

    Some instructions can be found here

提交回复
热议问题