How to disable password authentication for ssh in ubuntu 16.10/16.04

You can disable password authentication for SSH in server and allow key based authentication. Once you allow pub key based authentication, you need to keep your server key securely.

Change below mentioned parameter in SSH config file to apply the settings.
On Server (192.168.0.70)
$ sudo vim.tiny /etc/ssh/sshd_config

RSAAuthentication     yes
PubkeyAuthentication yes
ChallengeResponseAuthentication no
PasswordAuthentication  no
UsePAM  no

Restart ssh service
$ sudo systemctl restart sshd

Now generate key for authentication
Steps:
1. Generate public key and copy it to Remote/Server host
2. On Remote Host/public key this will save on location ~/.ssh/authorized_keys
3. After copy verify root access or from other user
4. Command for password less authentication
5. ssh-keygen  - Generate public and private key
6. ssh-copy-id –i – copy key on remote host

Generate key on Client system (192.168.0.75)
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shahzad/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/shahzad/.ssh/id_rsa.
Your public key has been saved in /home/shahzad/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:5LpdkMgxsb9Z6Nr8onozNBMA9biThnNEMC8WR+S/Dic shahzad@shahzad-virtual-machine
The key's randomart image is:
+---[RSA 2048]----+
|  =** .          |
|   B.o o         |
|  o =.= .        |
| . + =.B o       |
|  o * +.S .      |
|   + .++ =       |
|    E.+o+ .      |
|     =+*..       |
|    .o=++o.      |
+----[SHA256]-----+

Copy key to server using ssh-copy-id 
Syntax:
$ ssh-copy-id -i  ~/.ssh/id_rsa.pub user@server-ip
Example
$ ssh-copy-id -i .ssh/id_rsa.pub shahzad@192.168.0.70

Now access ssh server from linux host
$ ssh user@192.168.0.70

Access server from windows client
Download puttygen software and generate RSA Public key
After generating RSA key past this key in ~/.ssh/authorized_keys file on server.
 On Server (192.168.0.70) add key
$ vim ~/.ssh/authorized_keys 
Next save Private key in and add this in your putty software.



Add Private key in Putty
 
 You private key is added, now access server.


Server accessed successfully using key
Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment