栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

How to Create an SFTP User with Limited Access on Ubuntu

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

How to Create an SFTP User with Limited Access on Ubuntu

Since SFTP is secure than FTP, we always prefer the SFTP setup rather than FTP setup. (If you are new to SFTP, you can read about the key difference between FTP and SFTP. Others, read on.)  

Restrictive SFTP User

Please note, the below process is applicable to Ubuntu, and I assume you have already created the site

  Let’s assume the root directory of your site is /home/client_user. So when running the below commands, change /home/client_user to your site’s root directory.  

Create a New User

Now, lets create a new user named ‘client_user’ and assign that user /home/client_user directory as a home directory. Fire up your terminal to connect to your server. once you are connected, below command can be used to create a user. Make sure you replace client_user with the username you prefer and /home/client_user with the directory you want to assign to that user.  

sudo useradd -d /home/client_user client_user

 (Interested in reading about other options which can be passed to useradd? If yes, then you can read through these examples.)  

Set a Password

once the user is created, we need to set a password. To set a password for that user, execute the below command  

sudo passwd client_user 

We are ready with the new user now. Its time to make some changes in our SSH configuration.  

Restrict Access

Open the /etc/ssh/sshd_config file and append the below given code. (Remember to replace client_user with username you have created)
 

subsystem sftp internal-sftp 

Match User client_user 

ChrootDirectory %h 

AllowTCPForwarding no 

X11 Forwarding no 

ForceCommand internal-sftp 

%h stands for home directory.  

After doing the above changes, save the file and restart the SSH service. To restart SSH service, execute  

sudo service ssh restart 

Done! Now try logging into the system with the new user’s credentials, and check if everything is working correctly.  

One last tip: For those of you who get a ‘fatal: bad ownership or modes for chroot directory’ error, do not worry. When this issue occurs, we need to make sure that the home directory of a user is owned by root and no one else can write into that directory. So change the owner of home directory using the following commands:  
 

sudo chown root:root /home/client_user 

sudo chmod 755 /home/client_user

After changing the permissions, try it again. If it still does not work for you, do leave your comments. I will be more than happy to help you 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/311047.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号