This Tutorial Has Been Viewed 4,719 Times.
There are lot of requirements in the production environment where there is a need to have SSH without password prompt from one server to another under some id’s. But how to do that. Here is the solution and tips on how to approach this method without any bugs.
First of all lets take 2 servers
SERVER A and SERVER B
Here my requirement is to make some script which is in SERVER A copy some files from SERVER B and do some data updating activity in SERVER A.
Switch to the ID where you need the process to be running. [MAKE SURE THAT YOU HAVE HOME DIRECTORY SET FOR THE RESPECTIVE ID ON BOTH THE SERVERS]
Generate SSH keys in SERVER A.
ssh-keygen -t rsa
This will create PUBLIC KEY with an extension .PUB and another key which is the PRIVATE KEY inside the
Now Login to SERVER B and CHANGE DIRECTORY [cd command] to the home directory of the same id. Then copy the content of the PUBLIC KEY that was created in to a file named authorized_keys with command
cat <filename>.PUB >> authorized_keys
YOU ARE SET NOW
Logout of SERVER B and LOGIN WITH THE SAME ID ON SERVER A
ssh SERVER B
This will take you to SERVER B without any password prompt.
Make sure the home directory permission
/home/YOUR_ID This should be 755
The other files like PRIVATE AND PUBLIC KEYS and also the AUTHORIZED_KEYS should have only 600 permission. THIS IS A MUST OTHERWISE IT WONT WORK.
You will also be interested in ,
- Rsync command-line switches example
- LINDOWS SIMPLY A QUICK RECAP :-)
- Shell Scripts Part 1
- Shell Scripts Part 2
- Find the number of processor in linux using single command