LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash & ssh problem (https://www.linuxquestions.org/questions/linux-software-2/bash-and-ssh-problem-4175592873/)

sir89 11-04-2016 06:02 AM

Bash & ssh problem
 
I'm trying to log in a remote server with SSH by a bash script.
I'm using sshpass package too.
status="$(sshpass -p PASS ssh -o ConnectTimeout=10 USER@IP_REMOTE echo ok 2>&1)"

I'm trying to obtain de vale "OK" in the var status.
But always status is empty.

Need help :P

Turbocapitalist 11-04-2016 06:25 AM

Doing it with "sshpass" involves a lot of risks, one of which is showing your password to anyone logged in on your system. They can just look with "ps" and see it.

I don't have "sshpass" and can use command substitution $( ... ) with "ssh" just fine using keys for authentication. So it might be interfering with that.

Between the two problems, I'd recommend using keys for authentication instead.

Code:

status="$(ssh -i /home/user/.ssh/some_key_rsa -o ConnectTimeout=10 USER@IP_REMOTE echo ok 2>&1)"
Key-based authentication is considered best practice these days, anyway, so there are a lot of tutorials about using keys. Just remember that the public key goes onto the remote host and the private key stays on your client. Also, some of the guides are old, so ignore any that talk about using DSA. Use RSA or Ed25519 instead.


All times are GMT -5. The time now is 07:49 PM.