Batch Configure SSH Passwordless Login
Configuring SSH is fundamental operations work - sometimes the basics need revisiting.
Generate Public-Private Key Pairs
Ideally, everything should use public-private key authentication for passwordless direct connection from local to all database machines. Password authentication should be avoided.
First, use ssh-keygen to generate public-private key pairs:
Pay attention to permissions: SSH files should have permissions set to 0600, and .ssh directory permissions should be set to 0700. Incorrect settings will prevent passwordless login from working.
Configure ssh config to traverse jumphost
Replace User with your own name. Put in .ssh/config. Here’s how to configure direct passwordless connection to production database in a jumphost environment:
Copy Public Key to Target Machines
Then copy the public key to jumphost, DBA workstation, and all database machines.
Each execution of this command requires password input, which is tedious and boring. It can be automated through expect scripts or using sshpass.
Use expect for Automation
Replace <your password> in the following script with your actual password. If the server IP list changes, modify the list accordingly.
More Elegant Solution: sshpass
The downside is that passwords are likely to appear in bash history - clean up traces promptly after execution.
