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 04-11-2008, 05:03 AM   #1
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Rep: Reputation: 16
Can you specify a password without being prompted using "scp"?


I'm trying to write a script that copies a file to a remote computer, how can I use "scp" and put the password in the script so it doesn't need to prompt for user input?

I can't see a flag in "man scp" like the mysql "-p" flag, is there another way to do it?
 
Old 04-11-2008, 05:32 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
No. There is no way to give the password in clear text on the command line, otherwise it would be contrary to the nature of the Secure Shell. However you can alway set up Public Key Authentication. See man ssh for details (section AUTHENTICATION) or look for a tutorial on how to set up things using ssh-keygen.
 
Old 04-11-2008, 05:32 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
You need to generate a key pair and put the public key on the distant server.
try man ssh-keygen
 
Old 04-11-2008, 05:46 AM   #4
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
looks like the cause of this:

Code:
hashbang@stationX:~$ scp -o BatchMode=yes /home/hashbang/argle.txt chore@remote.box.net:/home/chore/argle.txt
Permission denied (publickey,gssapi-with-mic,password).
lost connection
hashbang@stationX:~$
I discovered the "batchmode" option, but now need to figure out the key-pair part.
 
Old 04-11-2008, 06:21 AM   #5
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
Okay I did this

Code:
The user creates his/her key pair by running ssh-keygen(1).  This stores the private key in
     ~/.ssh/identity (protocol 1), ~/.ssh/id_dsa (protocol 2 DSA), or ~/.ssh/id_rsa (protocol 2 RSA) and
     stores the public key in ~/.ssh/identity.pub (protocol 1), ~/.ssh/id_dsa.pub (protocol 2 DSA), or
     ~/.ssh/id_rsa.pub (protocol 2 RSA) in the user’s home directory.  The user should then copy the pub‐
     lic key to ~/.ssh/authorized_keys in his/her home directory on the remote machine.
Then tried to use this to go ahead with the copy:

Code:
hashbang@stationX:~$ scp -o BatchMode=yes /home/hashbang/argle.txt chore@remote.box.net:/home/chore/argle.txt
but still got:

Code:
Permission denied (publickey,gssapi-with-mic,password).
as a result.

I think this last bit in the man page is the cause

Code:
  The
     authorized_keys file corresponds to the conventional ~/.rhosts file, and has one key per line, though
     the lines can be very long.  After this, the user can log in without giving the password.
But I don't know where to find this "/.rhosts" file, does it mean on my local machine or on the remote machine? I don't see any .rhosts file listed in the "/home" directory or the "/home/.ssh" directory of the user on the remote machine... does it have to be the same username or can I have user "hashbang" on the local machine scping to user "chore" on the remote?

I've managed to confuse myself actually.
 
Old 04-11-2008, 06:24 AM   #6
brianmcgee
Member
 
Registered: Jun 2007
Location: Munich, Germany
Distribution: RHEL, CentOS, Fedora, SLES (...)
Posts: 399

Rep: Reputation: 39
Either use:

Code:
scp [options]  sourcefile  [user@]remotehost:destinationfile  <<EOF
password
EOF
Or better use passwordless authentication as stated above.
 
Old 04-11-2008, 06:39 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by hashbangbinbash View Post
I discovered the "batchmode" option, but now need to figure out the key-pair part.
The option BatchMode=yes simply disables queries for interactive input (password or passphrase) but don't give you passwordless access. If you have followed the steps in the manual page, you should have gained public key authentication.

If it doesn't work you have to verify if proper permissions are set. For example OpenSSH refuse authentication if the private key does not have permissions 600 (read-write for file owner only). Furthermore, you have to tweak the key generation if the remote machine does not run OpenSSH, but another flavour of the Secure Shell.

Finally, if you have changed the name of the keys (different from the default) you should specify the key name on the command line with the -i option
Code:
scp -i my_private_key file user@host:
Anyway, look at some tutorials (there are plenty of them in internet) and double check if you have correctly followed all the required steps.
 
Old 04-11-2008, 06:44 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by brianmcgee View Post
Code:
scp [options]  sourcefile  [user@]remotehost:destinationfile  <<EOF
password
EOF
You sure? Just out of curiosity I tried, but it didn't work for me. Anyway, apart security issues, this method can be difficult to achieve if the password contains special characters.
 
Old 04-11-2008, 06:45 AM   #9
hashbangbinbash
Member
 
Registered: Mar 2008
Posts: 106

Original Poster
Rep: Reputation: 16
thanks for all the fish.
 
  


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
scp error: xset: unable to open display "" [KIA]aze Linux - Networking 0 07-14-2007 05:18 PM
Creating a link from "." to other directory on SCP bujecas Linux - Security 4 02-01-2007 11:54 AM
"stalled" problem in " scp" command gentleshark Linux - Software 1 08-30-2005 03:08 AM
"stalled" problem in " scp" command gentleshark Linux - Networking 1 08-29-2005 01:41 PM


All times are GMT -5. The time now is 04:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration