LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2007, 07:54 PM   #1
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Question 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 !!
 
Old 10-19-2007, 11:34 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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.
 
Old 10-20-2007, 11:38 PM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Smile

Quote:
Originally Posted by macemoneta View Post
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.
 
Old 01-15-2012, 06:04 PM   #4
gbkabitz
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 01-20-2012, 03:09 PM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Thumbs up

Quote:
Originally Posted by gbkabitz View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass a c variable to a bash script? daYz Programming 3 09-28-2007 08:30 AM
scp, how to pass password in script ebel.velda Linux - Software 4 07-17-2007 05:13 PM
how to pass a keystroke to a bash script? minike Programming 5 01-21-2007 11:42 AM
Pass password with ssh command BruceC Linux - Newbie 2 05-12-2004 08:55 AM
pass root password in cgi script file explorer Linux - General 3 04-06-2004 10:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration