LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script : event not found when I echo my password into ssh (https://www.linuxquestions.org/questions/programming-9/bash-script-event-not-found-when-i-echo-my-password-into-ssh-4175567772/)

samanka80 01-24-2016 04:57 AM

Bash script : event not found when I echo my password into ssh
 
Hi all

I am automating some ssh connections on my laptop. I use this bash script:

echo my!pass | ssh hostname

I get this:

-bash: !pass: event not found

Well, my password contains ! and I really don't like to change it.

What does this mean and how can I fix it?

Please note: I can't use expect

Error seen on SunOS and MAC El Capitan

Thanks!

grail 01-24-2016 05:25 AM

Use single quotes to stop the shell from interpreting it.

samanka80 01-24-2016 05:41 AM

Thank you,

I try bot ' and /

In both cases, it skips everything after ' or /

Even doesn't get to ssh. It just prints:

echo my

Any idea how to stop process and move on to processing after?

Thanks

NevemTeve 01-24-2016 05:43 AM

Quote the command you tried and also the error message. Don't forget about [code] and [/code] tags.

eg
[code]
Code:

$ echo 'oh my!'
oh my!

[/code]

PS: don't even try to use ssh this way. Use certificates. https://www.digitalocean.com/communi...up-ssh-keys--2

samanka80 01-24-2016 06:20 AM

Many thanks

You are right, this is not the best idea :) However, servers are out of my hand so I should go with another way.

Ramurd 01-27-2016 07:49 AM

Automating connections with ssh is better, safer with public/private key anyway...
Code:

ssh-keygen
fill in the fields; password on the file is optional, so can be skipped.

Then you add the contents of id_rsa.pub (assuming you created an rsa key) to the target server user's authorized keys.
Code:

scp ~/.ssh/id_rsa.pub user@target.server:./my_pub_key.pub
ssh user@target.server
cat ~/my_pub_key.pub >> ~/.ssh/authorized_keys

# these are just for safety... better make sure the permissions are correct.
chmod 400 ~/.ssh/authorized_keys
chmod 700 ~/.ssh

Afterwards you can safely remove the remote .pub file, but you can keep it if you like...

Then try: ssh user@target.server
and you should see you can log on with no password, so no need to echo it plain-text in a script.


All times are GMT -5. The time now is 03:01 PM.