SSH key works from CMD line not script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users SSH key works from CMD line not script
# 1  
Old 07-20-2011
SSH key works from CMD line not script

OK , ..
This is an odd one. I have a new server and I need to have a tunnel open to it.
I have this exact process running on a few others but this new one I just got is not allowing the script to connect.
I set up my users account and ssh keys

from the server that will host the tunneling i type

Code:
ssh user_name@server_to_connect_to.com

it reads my key and lets me in .....
Now if I run my tunnel script it fails

Code:
/usr/bin/ssh -oKeepAlive=yes -i /home/path/to/ssh_tunnel_rsa_privatekey -C user_name@server_to_connect_to.com[/email]  -L3333:*:3306 -g -N &

in /var/log/secure i see

Failed password for user_name from xx.xx.xxx.x port 48443 ssh2
Any thoughts or suggestions ??
Thanks
Jeff

Last edited by jeffsandman0035; 07-20-2011 at 02:07 PM..
# 2  
Old 07-20-2011
Code:
/usr/bin/ssh -oKeepAlive=yes -i /home/path/to/ssh_tunnel_rsa_privatekey -C user_name@server_to_connect_to.com[/email]  -L3333:*:3306 -g -N &

have you tried this on the command line itself? in post you only tried
Code:
ssh user_name@server_to_connect_to.com

and if you may add -v.
# 3  
Old 07-20-2011
Yes I was running that from CMD line and added a -v
Code:
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /home/path/to/ssh_tunnel_rsa_privatekey 
debug1: read PEM private key done: type DSA
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: password

# 4  
Old 07-20-2011
i think you are pointing to the wrong private key file. make sure the path after the -i points to the private keys for the user. usually, this is located at /home/<user>/.ssh directory.
# 5  
Old 07-20-2011
I just checked , the remote server I am trying to connect to I copied the private key to my tunnel server and that is the name and path
Code:
/home/path/to/ssh_tunnel_rsa_privatekey

I just checked it again.... and its good chmod 600 like the rest .... i know i am missing something but its been 2 years since i first did this and cannot for the life of me remember what i am missing
< frustrating >
# 6  
Old 07-20-2011
hmmm it shouldn't be the private key that you will copy. you have to put your public key on the authorized_keys file on the remote server. This will be helpful. Read on the advance ssh part. Simple SSH Tutorial Outline
# 7  
Old 07-21-2011
OK .... some how for some reason someone updated SSH and any new tunnel that was not established you have to do this with the -g switch

Code:
/usr/bin/ssh -oKeepAlive=yes -i /home/path/to/ssh_tunnel_rsa_privatekey -C user_name@server_to_connect_to.com[/email]  -L172.36.x.xx:3318:*:3306 -g -N &

With the x.xx being the ip of the server hosting the tunnel

All our others are working fine since they have been established. We updated them in the event they drop .

Anyway who ever can close this Thanks everyone
Jeff
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Works on command line but not in script

OSX 10.9 I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently. Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly? ... (1 Reply)
Discussion started by: sudo
1 Replies

2. Windows & DOS: Issues & Discussions

Command works on CMD line but not in batch?

Hi All, This command works when I type it on but when I run the batch file it doesn't..any ideas why? attrib.exe * | find /c /v "" >filecount.txt (1 Reply)
Discussion started by: Grueben
1 Replies

3. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

4. UNIX for Dummies Questions & Answers

Works on command line but not in script

Hey guys. Hopefully this is an easy one but having reference similar problems on the web I still can't fix it. I am doing a recursive find and replace from a script. Of course I could just run the damn thing from the command line but it's bugging me now and want to get it working. grep -rl... (4 Replies)
Discussion started by: anthonyjstewart
4 Replies

5. UNIX for Dummies Questions & Answers

enable up arrow key to get last cmd..

Hello all, I wanted to know how can i enable the up arrow key to go to last cmd....on any UNIX system....looks like in some of my system(linux mostly) the up arrow key work to go to last cmd....but on hp-ux or sun...the up arrow key dose not work....is there some setting i can enable at terminal... (3 Replies)
Discussion started by: abdul.irfan2
3 Replies

6. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with , <F3> with and <E1> with . When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

7. Shell Programming and Scripting

find cmd works different on cron job ?

/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a -name '*.csv' \) -o -name '*_xyz_*' \) -mtime $DAYS_AGO -printf %f -printf "\n" | sort -r > $FILES The above command gives different results when run on a cron job. When run manually the result is accurate. (2 Replies)
Discussion started by: nuthalapati
2 Replies

8. UNIX for Advanced & Expert Users

script to monitor if ssh works.

Hi All, I have a setup of around 100 servers with atleast 10 users on each box.The public key from one server has been created and updated on all other servers , so that passwordless login can be done from any use. We recently had a problem that ssh keys on one of the system was changed and... (2 Replies)
Discussion started by: nua7
2 Replies

9. Shell Programming and Scripting

SSH script. (Assign $var to free cmd) ???

Running: GNU/Linux, 2.6.22.9-61.fc6 (hope that's the right info needed) I am trying give the amount of RAM and the % used. I am using free command. I am having some problems with this command code: 1)T = `free | grep Mem | awk '{print $2}'` F = `free | grep Mem | awk '{print $4}'`... (3 Replies)
Discussion started by: AngelFlesh
3 Replies

10. Shell Programming and Scripting

works from cmd-line but not in script

hi I'm trying to query a directory, check it's the right directory, return the results into a text file, put text file into an array and navigate the subdirectories and delete contents. find `pwd` -type d | grep TESTINGDIR > dirList.txt The txt file is created from the cmd-line but not in... (4 Replies)
Discussion started by: OFFSIHR
4 Replies
Login or Register to Ask a Question