I created user accounts on my linux server, then I disabled password logins. I configured ssh to not accept password logins and only accept ssh. I configured the ufw firewall and forgot to allow ssh port. So now I cannot login as no incoming connections are accepted, is there any thing I can do to reset this? The OS running is Ubuntu 14.04 LTS release and it is running inside a VirtualBox vm.


Recovery is similar to a lost root password (and might be easiest).

  1. connect to the console of your VM, using virtual box.

  2. a. if you can log from there, log as user, then sudo root, then edit sshd (and firewall rules) and reboot.

    b. if you can't log, neither root/nor user, reboot hosts, upon boot, select kernel (using arrows), edit (using e), then add init=/bin/bash to kernel line.

  3. remount / and /usr, then edit sshd_config

    mount -o remount,rw /
    mount /usr
    vi /etc/ssh/sshd_config
    vi /etc/passwd # see bellow
    vi /fire/wall/rules # (sic)

lost root password ?

to recover a lost root password, once you are in step 3.

  • passwd root
  • vi /etc/shadow, edit line like root:$6:salt$crypted:... remove $6$... up to but not including : (this will allow login with no password).
  • Hi archemar, I forgot to mention one more very important thing I am using Vagrant which is using VirtualBox so how can I connect to the console of the VM, because with vagrant I can connect only over ssh. Sorry for framing the question incorrectly – Sanik Aug 31 '15 at 12:48
  • How do you build you VM ? how do you power it off/on ? How do you add disk/LAN ? in this place you will find the console I told you about. – Archemar Aug 31 '15 at 13:52
  • Thanks, archemar found the console and followed the steps you provided, problem solved :) – Sanik Sep 1 '15 at 8:39


$ sudo ufw allow ssh/tcp
$ sudo ufw logging on
$ sudo ufw enable
$ sudo ufw status

If this does not help go to /etc/hosts.allow add sshd: ALLOW: ALL and restart the sshd, disable the firewall before restarting the sshd

  • Hi, lucifer I am running Ubuntu 14.04 LTS release through vagrant and because I configured ubuntu to block all incoming connections, I just cannot run the simple command "vagrant ssh" to connect to the linux vm. So I cannot run the commands you mentioned above at all. – Sanik Aug 31 '15 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.