1

I'm working on a script that will ssh from mac osx to a SmartOS (based on solaris) server and execute some commands but I'm stuck at the login part. I'm currently setup to be able to login with public key authentication which works fine manually but I'm being prompted for a password when I attempt to run the script.

Manual Login:

joyentmac2252:~ jessebutryn$ ssh root@X.X.X.X
[root@sup-jpc-west1 ~]# bash /root/sup-toolbox/toolbox
Enter your JPC Headnode username: jbutryn
Toolbox - Version 4.4.6 - It's Wednesday, this must be Devon (20161116)
---- Recent Changes ----

Replaced sdc-ldap/ufds with OpenLDAP client
vm/vmi now shows Swap
Moved creds to environment
Added random element to disabler string
fraud() speed up
Added over() for PD overrides
Added RAM to vms_by_pkg / fraud
Added dates to cust()
Big speed up for cust_vms(). You are welcome.

------------------------
[root@sup-jpc-west1 ~]#

The Script:

#!/bin/bash
#
SUPNODE="X.X.X.X"
ssh root@$SUPNODE
bash /root/sup-toolbox/toolbox <<-'EOF'
jbutryn
EOF

Script Results:

joyentmac2252:~ jessebutryn$ ~/Documents/scripts/incomplete/fraudcheck.sh
Password:

Anyone know what could be causing this password prompt?

1

For some reason your key-pair seems not to be used for authentication, you should try running the ssh-command in verbose mode ssh -vv (between one and three v's sets the verbosity level) inside and outside the script.

The output should tell you what's going on (post it here if you need further help).

  • Thanks! The debug didn't give me much good information other than the fact that it couldn't find the right key even though it was looking in the correct location. However I have modified the script to ssh -i <keyfile> now so ssh is working. – Jesse_b Jun 30 '17 at 21:23
  • Great, I guess you'll probably also have issues with the script actually being run locally instead of on the server? You could resolve this and simplify the code a bit by change the script to ssh root@$SUPNODE "echo jbutryn | /root/sup-toolbox/toolbox" (writing bash in front also is not required if you marked the file as executable with chmod +x <script>) – Folfy Jun 30 '17 at 21:33
  • Yes I am having issues passing the commands now. I tried the one line command you suggested above and it doesn't work. I've created a new thread for this issue @ unix.stackexchange.com/questions/374528/… – Jesse_b Jun 30 '17 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.