Hi;
I want to restrict my new created user. Only the /home/user section can be accessed. How can I do that?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Usually users don’t have access to run stuff outside of the files they have their user and group ownership. Having said that, you can use suduoers for that.
If you want to fully restrict that they can’t leave this folder. You can try Using Restricted Shell (rbash)
You can also use a restricted shell (such as rbash) to limit the user’s access to other parts of the system. This is a simpler method that doesn’t require setting up a full chroot jail.
rbash: To restrict the user, change their default shell to rbash (restricted bash). You can do this by editing the user’s entry in /etc/passwd:sudo usermod -s /bin/rbash user
/home/user: Create a bin directory in the user’s home and make symbolic links for the allowed commands.mkdir /home/user/bin
ln -s /bin/ls /home/user/bin/ls
ln -s /bin/cd /home/user/bin/cd
ln -s /bin/mkdir /home/user/bin/mkdir
PATH Variable: Add the following line to the user’s .bash_profile or .bashrc to ensure they can only execute commands from the bin directory in their home folder:PATH=$HOME/bin
export PATH
sudo chown root:root /home/user/.bash_profile
sudo chmod 755 /home/user/.bash_profile
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.