Public key/ private key
How to make the ssh connection on remote server from Ansible server
Step1: Generate key
ssh-keygen -t rsa -b 4096
Step2: Go to the path
cd /root/.ssh
ls
authorized_keys id_rsa id_rsa.pub known_hosts
Where id_rsa ----> private key (Used to login on the remote server without password)
id_rsa.pub ---->public key
Note: If someone gets access to this file (id_rsa), they can log in to any server where the matching public key is stored!
Step3: Copy the public key
cat id_rsa.pub
Step4: Paste the public key on remote server
vi ~/.ssh/authorized_keys or vi /root/.ssh/authorized_keys
Step5: Now we can login on remote server
From Private key: ssh -i ~/.ssh/id_rsa user@remote-server
From Public key:
Note: In case of ansible ansible-playbook playbook.yml --private-key ~/.ssh/id_rsa
Note: In file /etc/ssh/sshd_config, below parameter should be enable:
PubkeyAuthentication yes
PermitRootLogin yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
Then need to restart the ssh service
systemctl restart sshd
Comments
Post a Comment