LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-10-2009, 12:08 PM   #1
alex170872
LQ Newbie
 
Registered: Oct 2008
Posts: 18

Rep: Reputation: 0
ssh password from textfile


Hi,

has the original question been actually answered? Is there a way to use ssh (or mor urgent scp) with having the password in a file? I need to copy quite a lot of file to/from my work space, and for each scp I have to type my password. This is very annoying!
And yes, I have tried to setup the standard password-less ssh with keys, but for some unknown reasons this functionality is disabled. So the ONLY thing I can do is to stupidly type the same password dozen of times a day, except there is a way to do it with a password in a file...

Any help welcome.

Cheers
Alex

// Pruned from a vintage 2008 thread, please don't resurrect stale threads, TIA.

Last edited by unSpawn; 06-10-2009 at 01:51 PM. Reason: //moderator prunes post
 
Old 06-10-2009, 02:12 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by alex170872 View Post
Hi,

has the original question been actually answered? Is there a way to use ssh (or mor urgent scp) with having the password in a file? I need to copy quite a lot of file to/from my work space, and for each scp I have to type my password. This is very annoying!
And yes, I have tried to setup the standard password-less ssh with keys, but for some unknown reasons this functionality is disabled. So the ONLY thing I can do is to stupidly type the same password dozen of times a day, except there is a way to do it with a password in a file...

Any help welcome.

Cheers
Alex
My suggestion would be to write a simple expect script...

Code:
#!/usr/bin/expect -f
set user username
set pass password
set host hostnameoripaddr
spawn ssh -l $user $host
expect "assword:" 
send "$pass"
interact
This is off the top of my head and the syntax may need some tweaking, but you get the general idea.

Last edited by rweaver; 06-10-2009 at 02:20 PM.
 
Old 06-10-2009, 08:42 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by alex170872 View Post
I have tried to setup the standard password-less ssh with keys, but for some unknown reasons this functionality is disabled.
Trying to find out wouldn't hurt, wouldn't it?


Quote:
Originally Posted by alex170872 View Post
I need to copy quite a lot of file to/from my work space, and for each scp I have to type my password.
A password authenticates you as being a valid user on a local or remote system. Passwords often concern a personal account and certain privileges. Being careless about, giving away or otherwise making the password available to others may not be appreciated by remote admins. Ergo having a password in a script is not a good thing if someone else can read it. I suggest you try using ssh-agent before succumbing to using insecure kludges.
 
Old 06-11-2009, 03:32 AM   #4
alex170872
LQ Newbie
 
Registered: Oct 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Hi,

first a reply to the most recent email:

Quote:
Being careless about, giving away or otherwise making the password available to others may not be appreciated by remote admins.
Yes I understand. But these remote admins DO NO ALLOW the usage of keys to log in!! They have disabled that feature due to some unknown reasons!

Nevertheless, with the example given in the post before that I googled I found a script which I have modified as follows:

Quote:
#!/usr/bin/expect -f
set source [lindex $argv 0]
set dest [lindex $argv 1]
set timeout -1
spawn scp $source user@host:$dest
set pass "whatever"
expect {
password: {send "$pass\r" ; exp_continue}
eof exit
}
This works so far fine to copy one file around, but when I use placeholders it does not work. Lets call the script 'scp_to_host' then the folling happens:

./scp_to_host "data_*" /home/user
spawn scp data_* user@host:/home/user
user@host's password:
'data_*': No such file or directory
Killed by signal 1.

Any ideas how to modify the script so that wildcards are accepted as well?


Cheers
Alex
 
Old 06-11-2009, 04:27 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Tcl does not do filename expansion using the shell wildcard, but by means of the glob function. Once you've retrieved the list of files, you can use a for loop to copy each of them at a time:
Code:
#!/usr/bin/expect -f
set source [eval exec ls [glob [lindex $argv 0]]]
set dest [lindex $argv 1]
set timeout -1
set pass "whatever"
foreach file $source {
  spawn scp $file user@host:$dest
  expect {
  password: {send "$pass\r" ; exp_continue}
  eof
  }
}
Maybe there is a better method in order to avoid the foreach loop, which iterates the scp command N times, but I'm not good at Tcl scripting!
 
Old 06-15-2009, 12:34 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,363

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Have you asked the admins about being allowed to use public key login?
Another good suggestion from unSpawn is ssh-agent.
 
  


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
get "failed password" when scripts ssh in, but ok when I manually ssh in??? callagga Linux - Networking 4 02-06-2009 02:49 PM
ssh without a Password paragkalra Linux - Newbie 14 11-04-2007 02:05 PM
ssh with no password steinz Linux - Security 19 09-26-2007 12:11 PM
need help with no password ssh and ssh-agent hedpe Linux - Networking 3 02-08-2007 08:49 PM
SSH without password? Phaethar Linux - Networking 1 09-18-2004 06:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:06 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