I have two virtual machines VM1(Ubuntu) & VM2(Debian). VM1 has a single user "admin" & VM2 has two users "test1" & "test2". What I want is that only test1 was able to access VM1 through ssh whereas test2 user should not able to access VM1 through ssh.

i.e if I logged in as test1 user & type ssh [email protected] than remote machine should allow this user to access the machine(VM1) whereas if I'm logged in as test2 & try the same command than the remote machine(VM1) should restrict ssh access for this user.

2 Answers 2


You can restrict ssh access to ssh keys only (disable password login with PasswordAuthentication no) and only allow the key from test1 user account in ~admin/.ssh/authorized_keys on the VM1 machine.

Obs: the public key you will need to allow in admin@VM1 will be the public key /home/test1/.ssh/id_rsa.pub on VM2 machine (or something similar if you use rsa keys).


You have to set the AllowUsers (or AllowGroups) properties in the /etc/ssh/sshd_config:

AllowUsers test1

man of sshd_config

  • 1
    AllowUsers only works for the users present on VM1 machine i.e only allow ssh-login as admin user.However through AllowUsers host can be checked i.e [email protected] it will check the host to be allowed.But in my case Both the users are on same machine i.e VM2 ,so same host.
    – saurabh
    Jun 6, 2014 at 11:22
  • Now I understand. Maybe that is not possibile with ssh client. Try to read deeply the man of ssh_config file: openssh.com/cgi-bin/man.cgi?query=ssh_config Jun 6, 2014 at 12:31
  • It is possible to do so requiring ssh keys to login (disable password login and only allow keys for ssh).
    – laurent
    Jun 13, 2014 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .