How to restrict Ubuntu users to their own home directory?

This is specifically for my own use in my setting up for DigitalOcean but is likely equally applicable to generic Ubuntu administration.

Also, there are several other probable methods which one can find on the StackExchange network sites but the following method is the one which worked best for my particular use case.

After adding the new domain, creating the www folder and running the configuration process for certbot:

  1. Add a new user and setting the www folder as the user’s home directory

            useradd -d /var/www/ username
  2. Set the user’s password

            passwd username
  3. Set the appropriate permission

            chown -R username:username /var/www/
            chmod 701 /
            chmod 701 /var
            chmod 701 /var/www
  4. Restart the server

            service sshd restart
  5. The user can now login directly via a SSH client with the selected username and password to access the specified home directory directly.

21 August 2018