LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   pass password in bash script to SSH (https://www.linuxquestions.org/questions/programming-9/pass-password-in-bash-script-to-ssh-593155/)

vikas027 10-19-2007 08:54 PM

pass password in bash script to SSH
 
hi,

we can do this;
ssh -l <use name> <ip> "cmd to be executed"
ex:-
ssh -l root 192.168.1.1 "ls -al"


is thr some way to pass the password also along the the username.... say pwd is rehdhat


pls help !!

macemoneta 10-20-2007 12:34 AM

Take a look at 'man ssh-keygen' and 'man ssh-copy-id'. And never allow direct root access.

This overview will give you the steps.

vikas027 10-21-2007 12:38 AM

Quote:

Originally Posted by macemoneta (Post 2930372)
Take a look at 'man ssh-keygen' and 'man ssh-copy-id'. And never allow direct root access.

This overview will give you the steps.

Thanks macemoneta,

found your command useful

http://www.hostingrails.com/forums/wiki_thread/27

thanks a lot.

gbkabitz 01-15-2012 07:04 PM

bash SSH
 
I forgot to get the address where I stole this from, but this will let you log in just fine.

Let say you want to access to a machine with IP 10.0.0.4, and make sure you have command ssh, ssh-keygen, ssh-copy-id.

First, generate the ‘key’, the key will be used to open the remote machine’s door.

ssh-keygen

You will see something like that

Enter file in which to save the key (/home/myname/.ssh/id_rsa):

Whatever it appears just press enter until it ends, press enter for passphase as well.

Okay, the ‘key’ will be generated, something looks like ~/.ssh/id_rsa.pub

Copy over the ‘key’ to remote machine, and enter your password

ssh-copy-id -i ~/.ssh/id_rsa.pub mysurface@10.0.0.4


Done. Now you can ssh 10.0.0.4 with username mysurface without password.

ssh mysurface@10.0.0.4

vikas027 01-20-2012 04:09 PM

Quote:

Originally Posted by gbkabitz (Post 4575417)
I forgot to get the address where I stole this from, but this will let you log in just fine.

Let say you want to access to a machine with IP 10.0.0.4, and make sure you have command ssh, ssh-keygen, ssh-copy-id.

First, generate the ‘key’, the key will be used to open the remote machine’s door.

ssh-keygen

You will see something like that

Enter file in which to save the key (/home/myname/.ssh/id_rsa):

Whatever it appears just press enter until it ends, press enter for passphase as well.

Okay, the ‘key’ will be generated, something looks like ~/.ssh/id_rsa.pub

Copy over the ‘key’ to remote machine, and enter your password

ssh-copy-id -i ~/.ssh/id_rsa.pub mysurface@10.0.0.4


Done. Now you can ssh 10.0.0.4 with username mysurface without password.

ssh mysurface@10.0.0.4

Thanks gbkabitz, it has been almost 5 years since I asked this question. Now, I have mastered the art of it :)


All times are GMT -5. The time now is 10:32 PM.