|
楼主 |
发表于 2013-8-19 10:36:59
|
显示全部楼层
Creating SFTP accounts in Ubuntu for website files uploading
本帖最后由 MySense 于 2013-8-19 10:44 编辑
I have recently setup a new webserver, using Cherokee on Ubuntu, and then had to undergo the task of giving SFTP access to users, so that they could upload their websites and files.
Here’s the instructions that I used, which we’re taken from http://shapeshed.com/journal/chr ... on_ubuntu_intrepid/
but didn’t entirely work, so I’m re-writing them with what worked on my webserver.
The process consists of 2 main steps
- create a user with the relevant settings
- setup ssh to work with the sftp group and accept inbound SFTP style connections
UserStuff
CREATE SFTP ACCOUNTno need to use sudo if you’re logged in as root. Bad practice, I know, but takes out some confusion for people.
CREATE A USER and set their home directory as the root of their website folder- sudo useradd -d /var/www/thewebsite.com username
复制代码 CREATE A PASSWORDMODIFY THE USER TO ADD THEM TO YOUR NEW SFTP GROUP- sudo usermod -g sftp username
复制代码 MODIFY THE USER AND DENY ACCESS TO A SHELL – I.E THEY WON’T BE ABLE TO LOGIN TO A SHELL- sudo usermod -s /bin/false username
复制代码
SSH Stuff
EDIT YOUR SSH CONFIG FILE- sudo vim /etc/ssh/sshd_config
复制代码 CHANGE THE SUBSYSTEM lineFirstly comment out the following line- # Subsystem sftp /usr/lib/openssh/sftp-server
复制代码 Then add- Subsystem sftp internal-sftp
复制代码 Then add this to the bottom of the file- Match group sftp
- X11Forwarding no
- ChrootDirectory %h
- AllowTcpForwarding no
- ForceCommand internal-sftp
复制代码 at this point I decided to restart ssh just to make sure the changes were ok- sudo /etc/init.d/ssh restart
复制代码 If any of the lines are formatted badly ssh may not restart.
Finally you need to set the permissions of the website folder to allow access to the files for your new user. Basically, root needs to have access to the root website folder and your new user needs access to the files and folders beneath.
My websites live in /var/www. To check I issue
This shows me that all the website root folders are owned by root root, which is correct. If they are not you need to
- chown root:root thewebsite.com
复制代码 Then we need to set the permissions beneath this folder for the new user. So I
- cd /var/www/thewebsite.com
- chown username:sftp -R *
复制代码 Now when I issue an ls-l I can see all the files owned by my user and in the group SFTP
and That’s It
Now users can be given the username and password setup, use a STFP client, such as CoreFTP Lite, and SFTP into my Ubuntu box. They ONLY have access to their folder as the root of their access is their home folder. they cannot browse anywhere else.
|
|