SuSE Scripting Automation: Fully Automatic Login
Posted by sastri
Look! No Password!
A little tid-bit that will help you set up fully automatic access without using a password and will work great for scripting! If you are running scripts on an array of servers and want to use a low overhead method, this is the way to get multiple bangs for your buck!
On the "server" machine.
- Enter the .ssh directory
cd .ssh
If the directory does not exist create it - ssh-keygen -t rsa
- cat id_rsa.pub >> authorized_keys
- chmod 600 authorized_keys
- rm id_rsa.pub
mkdir .ssh
On the "client" machine.
- cd .ssh
- scp ip_of_your_server:.ssh/id_rsa ip_of_your_server.rsa
- chmod 600 ip_of_your_server.rsa
- Add your server to the ssh config file:
echo "Host ip_of_your_server" >> config - echo "IdentityFile ~/.ssh/ip_of_your_server.rsa" >> config
Now Test the setup from the client.
- ssh ip_of_your_server
- scp file ip_of_your_server:.
Using it within a Bash script.
# Define you servers
server_names() {
echo -en "IP_of_your_Server"
}
# Loop through servers and save outout into a report
for srv_name in $(server_names)
do
echo -e "\nServer: $srv_name"
HOST="$srv_name"
ssh USER@$srv_name "Do Commands" | while read -a REPORT_OUT
done