Often an automated process will completely fill up the main drive and I won't even be able to login over SSH to fix it. How do I prevent all the space from being used, so that I can always login to my headless server with SSH and delete something?
can't create socket: No space left on device
(There are an infinite number of things that could fill space. A good answer will not care which of them is doing it, but will prevent them from using the space that ssh needs to function.)
Several Linux filesystems, including the most common one
ext4
, have a feature to deal with this exact problem: by default 5% of the space on the drive is reserved for the root user. This ensures the administrator can always log in to fix out-of-space problems.TL/DR:
Enable the root account in Ubuntu
Configure the SSH daemon to allow root login
Login with the root account whenever lack of space is preventing normal login
A security note is in order: allowing root logins should be done with care. In particular, it's recommended to allow root login via certificates only, no password logins allowed. In any case, make sure when you define the root password to make it a strong one (it should rarely be needed interactively anyway, so go to town on the password length).
Well first try to figure out what is filling up your space. Try to remove any bloatware or background processes which might be filling up your space. You can use:
sudo iotop -a
or anydf
commands. Then if there is necessary application which can't be stopped then make a cron job or a habit of regular cleanup of cache and temprary files. There are many ways to clear up your cache.Try:du -sh /var/cache/apt/archives
sudo apt-get clean
sudo apt-get autoremove --purge
sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches