4

I'm writing a script for using SSH "profiles", ~/scripts/ssh-profiled.sh

PROFILE=`cat ~/script/ssh-profiles/$1`
echo [ssh $PROFILE]
ssh $PROFILE

~/scripts/ssh-profiles/tummi

-i ~/Dropbox/security/key-nopass/key-nopass.pvt [email protected]

When I run the script, it fails:

bart@bart-laptop:~$ script/ssh-profiled.sh tummi
[ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt [email protected]]
Warning: Identity file ~/Dropbox/security/key-nopass/key-nopass.pvt not accessible: No such file or directory.
[email protected]'s password:

But this works:

bart@bart-laptop:~$ ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt [email protected]
Linux tummi 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
Ubuntu 10.04.1 LTS

Welcome to the Ubuntu Server!

Is there an error/gotcha in my script?

2
  • 1
    As an experiment, add echo ~ to the script somewhere. Commented Dec 29, 2010 at 20:50
  • Any experiment is useful to try, but that one will just get you more confused as you'll see ~ expanded to the home directory but the expansion still will not work for ssh. See Victor's answer with "eval" for why. Commented Dec 29, 2010 at 21:16

4 Answers 4

5

Change 1st line to

eval PROFILE=`cat ~/script/ssh-profiles/$1`

For explanation see here

Sign up to request clarification or add additional context in comments.

1 Comment

Beat me to it. An alternative is "eval ssh $PROFILE" which is how I was going to answer.
2

The ~ in your file needs to be the full home directory path, it's not getting expanded.

Comments

1

My guess is the "~/" is not being interpreted as expected when passed in that way. Try using an explicit full path.

Comments

0

What are the permissions on the .pvt file? If only you have read access, and no one can execute it, then your script might not be able to even see the file. That could be why you are getting the "...not accessible: No such file or directory." message.

1 Comment

"No such file or directory" (ENOENT) is not a permission error (EACCES).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.