SSH questions

#!/bin/ksh
ssh-keygen -t rsa

for host in `cat filename`
do
ssh $\{LOGNAME\}@$host "mkdir -p ~/.ssh"
echo "Please key in password for host:"$host" (only if prompted)"
________________________________________________________
scp ~/.ssh/id_rsa.pub $\{LOGNAME\}@$host:~/id_rsa.pub
ssh $\{LOGNAME\}@$host "cat ~/id_rsa.pub >> ~/.ssh/authorized_keys"
ssh $\{LOGNAME\}@$host "chmod 644 ~/.ssh/authorized_keys"
___________________________________________________________

done

How the commands between two lines will run without asking for password from script.

Please explain

They will ask for your password, afterwards SSH and SCP will not because you have setup a shared key in the remote hosts ~/.ssh/authorized_keys file and in your local hosts ~/.ssh folder.

If you want them not to ask for your password then you could write an expect(1) script to do it but that would be poor security because the expect(1) script would have to have tour password in it.

See: http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/scripting/5.html for an example expect(1) script.

Take a look at ssh-agent which would ask for your password once per session and the provide it for you, take a look at: http://mah.everybody.org/docs/ssh