Posts Tagged ‘lock ssh key’

Lock and Delete SSH Keys for user account

Lets think of a scenario that a user wa using all your critical resources on the remote server via ssh.Now for some reason he is leaving the company.So we need to take all tha access from the user as it is a security risk.So how to do that?please find below the commands to lock and delete a user account on various systems.

The first step is to disable user login using command as follows:

In Linux

# passwd -l userName

In FreeBSD

# pw lock userName

In Solaris / HP-UX UNIX

# passwd -l userName

The next step is to Remove SSH Keys

There are two ways to accompany this task.


in linux/unix environment the ssh keys are stored inside users home direcory.You will find it at


We can simply rename the directory or delete the directory:

#mv /home/userName/.ssh /home/userName/nosshlogin
# rm -rf /home/userName/.ssh 


You can also edit $HOME/.ssh/authorized_keys file and remove public key. This will delete login from user’s computer to your server. Finally, you can always delete user from your system using the pw (FreeBSD) or userdel (Linux / UNIX) command.

Categories: Linux Tags: , , ,