Now, I would try to execute the script in the remote host.
# ssh <user and REMOTE_IP> /home/user/testsuite/sample.sh hello world Password : hello world
Here, the sample.sh script looks something like this:
sample.sh
#!/bin/bash echo -e "$1 $2"
So, if I execute the script with two command-line arguments, it will print the arguments in a line.
Disadvantages of password-based authentication in SSH
I want to automate the whole procedure. i.e. I want to execute a script in my local machine, which would connect with the remote machine and execute the test scripts in an automated way without any human interactions.
But, in the current setup, there is a problem. I would have to give passwords every time the automated script residing in my local machine would connect to the remote machine for the execution of any test script.
Configuring SSH Key Authentication
If I use RSA keys for authentication in SSH, the problem would be easily solved. I would need to generate an RSA private-public key pair in my local machine and copy the public key to the remote machine over SSH. Then, every time my local machine would try to connect with the remote machine over SSH, the RSA keys would be used for authentication instead of passwords.
The local host would first establish an SSH connection with the remote host and decide on the symmetric key using which the communication would be encrypted. Then, the local host would send the RSA key ID. The remote host would verify the key ID with the stored RSA public key. If it matches, then the remote host will proceed with the authentication procedure.
Firstly, I would need to generate the RSA keys and copy the identification in a remote host so that while authenticating, it will use that information.
The steps are simple :
Firstly, I would generate an RSA private-public key pair in my localhost :
# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/user/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user/.ssh/id_rsa. Your public key has been saved in /home/user/.ssh/id_rsa.pub. The key fingerprint is: ******************* The key's randomart image is: +--[ RSA 2048]----+ ... +-----------------+ #
Next, I would copy the identification in the remote host :






0 Comments