LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-05-2012, 06:44 AM   #1
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Rep: Reputation: 12
How to use scp with the password ?


Hi,

I am using scp command to copy one file to remote machine as follows

Quote:
scp <localfile> root@10.0.2.5:/roo/
so it asking for the password,
my doubt is how to pass the password along with the command so i don't have to give password again.

I searched and find out about the keyfile set up but I do not need that idea .
I want to use the password.

So,kindly tell is it possible to use password if yes then how and if not then is there any other way to copy a file/directory in one command itself with out prompting for password.

kindly tell some suggestion ,it is needed for my work.
Thanks
 
Old 07-05-2012, 06:49 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
passwords should always be entered manually. Your requirements fit *EXACTLY* with a preshared key. Why would you not want to do that?
 
1 members found this post helpful.
Old 07-05-2012, 07:30 AM   #3
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Original Poster
Rep: Reputation: 12
Thanks for the reply,
I do not want the idea of key file because,in my project I may not always need to have that key file set in all the target machines adn also local machine for all the target file.

simply i have the password and a shell script to copy a file to all the machines.but it asking password so how to do this .


Thanks
 
Old 07-05-2012, 07:45 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
In that case I would recommend to use expect. but keep in mind that hardcoding a password in a script is a very bad habit security wise.
 
1 members found this post helpful.
Old 07-05-2012, 07:54 AM   #5
uk.engr
Member
 
Registered: Apr 2012
Posts: 131

Rep: Reputation: Disabled
Quote:
simply i have the password and a shell script to copy a file to all the machines.but it asking password so how to do this .
I think you may do this via "expect".


#!/usr/bin/expect
spawn scp localfile root@192.168.1.13:/root/
expect "*password:*" {
send "mypassword\r"
}

This will automatically put password when password's prompt will be detected. Note in your case you have to connect your shell's script with this expect's script.

Last edited by uk.engr; 07-05-2012 at 07:58 AM.
 
2 members found this post helpful.
Old 07-05-2012, 08:27 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Can I just add further support to acid_kewpie & TobiSGD's advice: hard-coding a password is a really bad idea.
 
Old 07-06-2012, 01:44 AM   #7
jsaravana87
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 558
Blog Entries: 5

Rep: Reputation: Disabled
Hi
Keeping the password on shell script is very idea try to use ssh keygen instead of password.But Any way you can use these

sshpass -p 'password' scp user-name@scp-server-ip-addressath-of-the-file/file-name destination-location
 
1 members found this post helpful.
Old 07-06-2012, 02:20 AM   #8
uk.engr
Member
 
Registered: Apr 2012
Posts: 131

Rep: Reputation: Disabled
Great sshpass is more better than expect
 
Old 07-06-2012, 02:50 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Quote:
Originally Posted by pradiptart View Post
Thanks for the reply,
I do not want the idea of key file because,in my project I may not always need to have that key file set in all the target machines adn also local machine for all the target file.

simply i have the password and a shell script to copy a file to all the machines.but it asking password so how to do this .


Thanks
You should look to adjust your requirements so that they do fit in line with preshared keys. they exist for a reason, and anything else is a hack.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] ssh scp key not working to ssh/scp without password rjo98 Linux - Newbie 9 08-22-2011 05:28 PM
sftp/scp without password chuikingman Linux - Server 9 08-21-2009 07:50 AM
scp needs three times password in wrong password case!!! JATA01 Programming 6 12-01-2008 06:28 AM
SCP without Password help ignignokt Linux - Networking 3 01-02-2007 12:59 PM
scp and no password mikeyt_333 Linux - General 2 03-26-2002 04:33 PM


All times are GMT -5. The time now is 12:15 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration