LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-04-2016, 06:02 AM   #1
sir89
LQ Newbie
 
Registered: Oct 2016
Posts: 12

Rep: Reputation: Disabled
Smile 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
 
Old 11-04-2016, 06:25 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727Reputation: 3727
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.
 
  


Reply

Tags
bash, remote, ssh



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script, if else statement to ping & ssh connection to correct i.p. VipX1 Linux - Newbie 2 12-31-2009 11:05 PM
Chroot SSH problem: ssh working, not SFTP & SCP. NaCo Linux - Security 3 02-01-2009 02:23 AM
ssh & x11 problem paragkalra Linux - Networking 2 06-11-2008 11:34 PM
[putty&ssh] Who is really good & expert in ssh https tunnelling and firewalling ? Xeratul Linux - General 12 12-03-2006 03:22 AM
ssh && su problem... branque Fedora 3 08-13-2005 05:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration