Search Suggest

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 (
$ 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
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 (
$ 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/
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.      |

Copy key to server using ssh-copy-id 
$ ssh-copy-id -i  ~/.ssh/ user@server-ip
$ ssh-copy-id -i .ssh/ shahzad@

Now access ssh server from linux host
$ ssh user@

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 ( 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

Đăng nhận xét