ssh connection through shell script with no interruption


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh connection through shell script with no interruption
# 1  
Old 09-06-2011
ssh connection through shell script with no interruption

Hi all,

I need ssh in shell script. My requirement is:
- Take user_name and password from user (in PHP)
- Pass this to shell script which will:
- connect via ssh
- Run sql query
- Pass the results back in PHP
- Put the results to website.

I know PHP has libraries for ssh and ftp, but in my system all are disabled. So, I need to write script for this. I have already done FTP, but I am not getting any luck with ssh.

Everything else on the above list I can do, I just need ssh connection through script with no interuption.

I am using Solaris. Thanks for your help.

---------- Post updated at 01:54 PM ---------- Previous update was at 01:49 PM ----------

Here is the code I used for FTP...


Code:
u_id=$1; passw=$2; ip=$3;           // uid, password and ip taken from PHP
ftp -inv $ip <<SCRIPT
user $u_id $passw
mget *
bye
SCRIPT

I need similar thing to be done with ssh, just instead of mget, I need to run queries.
# 2  
Old 09-06-2011
ssh is designed to prevent you from using passwords passed along in plaintext because that is extremely insecure. So does any sane authentication system, like su and sudo.

Could you handle the password in the PHP script itself then, and after the PHP script decides its authorized, connect to the appropriate site with noninteractive SSH keys?

---------- Post updated at 12:06 PM ---------- Previous update was at 12:03 PM ----------

Another method would be editing /etc/ssh/sshd_config in the system you're connecting to to be more lax in its security PasswordAuthentication yes which would allow you to use the PEAR-ssh2 PHP module on your system. See ssh2-connect and related calls.
# 3  
Old 09-06-2011
Quote:
Could you handle the password in the PHP script itself then, and after the PHP script decides its authorized, connect to the appropriate site with noninteractive SSH keys?
Exactly this is my problem.... How would I authorize users in PHP itself while logging into remote machine? I don't know any other method than ssh.

Also I could not find /etc/ssh/sshd_config in the system I am connecting to. There is sshd_config in /etc/ but I am unable to open it.
# 4  
Old 09-06-2011
Quote:
Originally Posted by shekhar2010us
Exactly this is my problem.... How would I authorize users in PHP itself while logging into remote machine?
Something like

Code:
# in the shell
$ printf "%s" "12345" | sha1sum
8cb2237d0679ca88db6464eac60da96345513964  -
$

Code:
// in PHP
if(sha1($password) == "8cb2237d0679ca88db6464eac60da96345513964")
{
        // Connect using keys, not passwords
        system("ssh -i /path/to/id_dsa $username@host"); // or however you want to connect to ssh
}

You don't even need to store the password anywhere Smilie For instructions on how to generate these key files and send them to the computer you want to connect to, google passwordless ssh.

Quote:
There is sshd_config in /etc/ but I am unable to open it.
If you don't have root privileges on the system you're connecting to, that won't work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

2. UNIX for Dummies Questions & Answers

Script that tries to connect via SSH till connection is up

Hey, I need a script that tries to connect via SSH to a remote server and that remote server might not be up yet, so retry until succeed the error message I get if the server is not up yet is: ssh: connect to host 127.0.0.1 port 40001: Connection refused any idea of a good way to do it ? ... (5 Replies)
Discussion started by: OdedOvdat
5 Replies

3. AIX

ssh interruption after aix os upgrade

Hi Through nimadm (alt_disk_install) we done aix os upgrade in 3 lpars from aix 5.3 to aix 6.1. upgrade was successful. After the upgrade users complained on their ssh keys. Does upgrading aix version affects the user's ssh keys ? If so please suggest on options to correct them. (1 Reply)
Discussion started by: newtoaixos
1 Replies

4. Shell Programming and Scripting

connection of JSP using SSH to access Shell script

Hello, I am not sure if I am posting in the right forum. A website is running on a server with <ip1> in unix. It's written in JSP. I need to add a link on the page, which will on-clicking ask for username and password to enter into another server <ip2> and gets all the files from a... (1 Reply)
Discussion started by: shekhar2010us
1 Replies

5. Shell Programming and Scripting

How to automate SSH remote connection with a shell script

Hi Guys! I am trying to write a shell script for automated ssh. vairable user and passwd have initialized correctly, but when I use the following it still prompting me for the password. #!/usr/bin/bash user='root@10.14.76.225' passwd='admin' ssh $user $passwd uptime exit I... (3 Replies)
Discussion started by: pinpe
3 Replies

6. Shell Programming and Scripting

SSH Connection drops - but does my script keep running?

Hello there. I'm fairly new to Linux, but I am connecting via SSH and PuTTY to a remote server, and I am running a fairly heavy MySQL script in a PHP page. Our connection here is dodgy to say the least and I get continuous disconnections. My question is, when I get disconnected, does my... (4 Replies)
Discussion started by: christatedavies
4 Replies

7. Shell Programming and Scripting

how to terminate ssh connection without terminating script

Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Discussion started by: fozay
1 Replies

8. Shell Programming and Scripting

ssh connection script

Hi all, I'm writing a script that chooses the best computer available in an open lab. The script works great except every now and then there is a dead computer in the lab that begins the ssh handshaking, but freezes after the following: debug1: Offering public key: When the script happens... (2 Replies)
Discussion started by: x-375HK-x
2 Replies

9. Shell Programming and Scripting

Remote SSH Connection Using Script

Hi, I am new to Shell Scripting. Can anybody help me in writing a Script Which Could Login from a Unix box to a Remote Unix box which accepts the user credentials automatically and display the result for checking the Disk Space Utilisation (Without running any SSH agent). (1 Reply)
Discussion started by: ajith_tg
1 Replies

10. Shell Programming and Scripting

Testing ssh connection from KSH script

Hi. I have a kornshell script that runs on a daily basis as a cron job. Part of what the script does is copy the folder contents from another server to the current server (server where KSH script is running). I have a scp command, as follows: scp $REMOTE_HOST:$REMOTE_FILE_DIR/* $TMP_DIR ... (8 Replies)
Discussion started by: dmilks
8 Replies
Login or Register to Ask a Question