Two types of authentications
1) Username and Password
2) Key based authentication
Username & Password: Create new user and set password, Which very common method
2) Key based authentication: Create user generate public/private key
Fresh user :-
Generate public/private key
Public key save on server and private key for user which user want access remote.
When you generate key then default one directory create under user home direcotry .ssh/
id_rsa {Private Key}
id_rsa.pub {Public Key}
publickey store under /home/user/.ssh/authorized_keys
When you copy authorized key then check file permission if not then provide though below command
chown username /home/user/.ssh/authorized_keys (file ownership will change)
Now user will access remote by key.
Requirement exiting user remote access via username & password now we have provide only key based authentication
Generate public and private key.
#ssh-keygen (Generate public and private key under /home/user/.ssh/
id_rsa (private key)
id_rsa.pub (public key)
#ssh-copy-id username@ip address (This cmd for copy public key in user home directory and create file like Authorized_keys)
Enter
Asking the user password (AWS Linux ec2 there password authoentication is disable so we have enabled from vim /etc/ssh/sshd_config then search PasswordAuthentication by default its no sow we have replace yes then save file and restart ssh service.
#systemctl restart sshd
Then agin use below
ssh-copy-id username@ip address
You can see message below message after enter password of user.
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'ravikant@172.31.83.133'"
and check to make sure that only the key(s) you wanted were added.
now lets see user is accessble remote
No comments:
Post a Comment