Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

(1) I want to upload some files to a server

for (( i=0 ; i < 23 ; i+=1 )); do  
    echo mypassword | scp tim@xxx.xxx.xxx.xxx:project/$i/train10000/finer_search_c_g ~/project/$i/train10000/  
done

I hope that by pipe my password to scp, the loop will be executed without interaction. However it still asks me to manually input the password. How should I specify mypassword to scp?

(2) I do not use authentication keys generated by ssh-keygen because the server actually is a head node of a cluster. I found that if I use ssh-keygen to generate authentication keys, the files under ~/.ssh will make the access between nodes requiring password, which I cannot find a solution. Is it possible to make the access between nodes with empty password while using authentication keys to access head node from outside the cluster?

THanks and regards!

share|improve this question

3 Answers 3

up vote 8 down vote accepted

Use a key file. Place the private keyfile on your client and use ssh-agent to keep the key file loaded in memory, decrypted. Place the public key file on each of the systems you want to access.

Use authentication forwarding to create connections between various hosts without being prompted for authentication.

share|improve this answer
    
and you can use an empty passphrase for that keyfile to speed things up –  lorenzog Feb 8 '10 at 23:26
    
key file for sure, the only other option is to use the expect command to have the script input the password for you, but don't do that, use keys. –  CarpeNoctem Feb 8 '10 at 23:57
    
Thanks! Could you be more specific please? I still dont know how to operate. –  Tim Feb 9 '10 at 0:28
    
Is it possible to specify my password as command line argument to scp? –  Tim Feb 9 '10 at 0:30
2  
superuser.com/questions/8077/… –  grawity Feb 9 '10 at 11:17

scp/ssh will test the input stream to check if it is a TTY and if not will try alternate ways to get the password, so plain piping will not work (because the pipe is not a tty).

share|improve this answer
    
Thanks Cairo! Some questions, what is a input stream by TTY, for example? What are the common ways for a input stream? How to know what type of input stream a stdin input to a command is? For example that of ssh/scp. –  Tim Feb 26 '10 at 1:26

You need to copy the public key to the file .ssh/authorized_keys on the system you want to connect to.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.