I am logged into a remote ubuntu server, and I accidentally erased the entire /home/username/ directory for the current user. The only thing left is a hidden directory called .gvfs. I don't need anything of the Documents/Music/etc.

Now it is not letting me cd into the /var/www/ directory, which has permissions 666 and it is owned by the current user.

I am afraid to disconnect from my ssh session because I don't know if I will be able to get back on. Have I permanently created a problem? Is there a way I can replace the most important files to the /home/username/ directory?


** EDIT **

Thanks everyone for the help. I figured the problem with cd into the /var/www/ was actually my permissions in the /var/www/ directory. It was set to 666, changed it to 755 and everything was good again. It doesn't look like anything systematic was ruined by deleting the contents of the user folder.

  • 1
    Do you have backups? Restore from backup is the only solution I can think of. – user68186 Jun 27 '13 at 12:43
  • Unfortunately I don't have the backups going yet. +1 for backups. – jeffery_the_wind Jun 27 '13 at 12:44
  • If you reboot the system Ubuntu will recreate all -system- related files inside /home/$USER when the users logs in. Of course this will not restore user files and/or settings that the user changed. – Rinzwind Jun 27 '13 at 12:55

The system should continue to be completely usable in itself with files in a user's home directory all deleted. You certainly shouldn't have any problem cd'ing to /var/www.

But directories need to have execute permission for users to be able to traverse to them. You said /var/www was 666, which doesn't include any execute bits, so it sounds like you have a separate problem. Try: sudo chmod 755 /var/www to set /var/www back to reasonable permissions.

You may also find it useful to copy the contents of /etc/skel to the home directory where you have deleted everything. If you do, make sure the files you copy end up having the owner and group of the user. This is done when you create a new user and provides a set of sane defaults for new users to start with.

You also said you were ssh'd in as this user. To make sure you can do so again, you'll need to restore the ~/.ssh directory with 700 permissions, and make sure that ~/.ssh/authorized_keys contains your public key. You can test this with a different ssh session before you log out of your original one.

| improve this answer | |

If you log into ssh with a password, you need not worry about your ssh session. However, if you login without a password, ie with an ssh key, then the most important file to restore now is the one allowing your ssh access. For this, you need to find the contents of the file


on your LOCAL computer, and put it in the file


on your REMOTE computer.

Use a second, simultaneous ssh session in another terminal window to see whether you can still login.

| improve this answer | |

try pressing Ctrl + Alt + T to launch Terminal

Next, type in


to run the file manager and try to undelete

If this doesn't work, you could try manually adding the required folders either in nautilus if it will let you, or in Terminal using the mkdir command, create a Home folder then folder which is your username so that you can get to ~ or /home/username then you'll need to create:

  • Desktop
  • Documents
  • Downloads
  • Music
  • Pictures
  • Public
  • Videos

Hopefully this will get you back and running


| improve this answer | |
  • 4
    He says he is using ssh ;) Your method requires a desktop session. – Rinzwind Jun 27 '13 at 12:57
  • Ooops! I missed that! – SimplySimon Jun 27 '13 at 15:28

You could try out http://extundelete.sourceforge.net/ to see if you're able to recover the directory and files. If possible, make sure nothing more is written to the disk before you have tried to get the old files back.

| improve this answer | |

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.