The best way to do this is to create a chroot jail for the user. I'll clean up the answer here when I get home but I posted the solution on my blog.
https://thefragens.com/chrootd-sftp-on-mac-os-x-server/
Below are most of the instruction from the above post.
First, you should create the new user in Workgroup Admin and either assign them access privileges for SSH via Server Admin or assign them to a group that has SSH access privileges. Further discussion is below.
From the Terminal, start off right.
sudo cp /etc/sshd_config /etc/sshd_config.bkup
sudo chown root /
sudo chmod 755 /
sudo mkdir -p /chroot/user/scratchpad
sudo chown -R root /chroot
sudo chown user /chroot/user/scratchpad
sudo chmod -R 755 /chroot
Every additional new user added will then be something along the lines of the following.
sudo mkdir -p /chroot/user2/scratchpad
sudo chown root /chroot/user2
sudo chown user2 /chroot/user2/scratchpad
sudo chmod -R 755 /chroot/user2
Every folder it the path to the chroot jail must be owned by root
. I don't think it matters what group the folder is in. What I did above was to
- backup
/etc/sshd_config
- change ownership of the root directory to
root
- change permissions of the root directory to 755
- create a chroot folder
- create a user folder inside the chroot folder
- create a folder inside the user folder that user can modify
- set ownership and permissions
Now to edit /etc/sshd_config
to the following.
#Subsystem sftp /usr/libexec/sftp-server
Subsystem sftp internal-sftp
Match User user
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
ChrootDirectory /chroot/user
This creates a chroot jail that when the user logs in will drop them into the folder /chroot/user
, in that folder is a folder they can add things to /chroot/user/scratchpad
.
If you want to create a Group in Workgroup Admin for 'Chroot Users' then add the new users that you created in Workgroup Admin to the Group you won't have to keep editing the /etc/sshd_config
file. Instead of the above, add the following. Make sure you add the 'Chroot Users' group to the SSH access ACL in Server Admin.
Match Group chrootusers
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
ChrootDirectory /chroot/%u
To test whether the above is working, issue the following from the terminal.
$ sftp user@domain.com
Password:
sftp>
The following article may help your problem. :)
Mac OS X: Require Password at Single User Mode:
By default, Mac OS X will simply give you a shell when you perform a Single User Mode startup. However, you can force OS X to ask for a password in order to gain shell access. To do so, vi the /etc/ttys and change secure to insecure. Once you have done so, create a password in /etc/master.passwd for root.
Best Answer
The
_www
user is designed to never have a shell and many of the user attributes needed for ssh to run are missing. Once you log in as any other admin user, you can easily sudo over to user_www
to get file permissions correct.You can compare with a real user to see the missing attributes. If you want to hack, you could try making the NFSHomeDirectory writable and editing the shell - but that would leave all sorts of user files in /Library/Webserver - and your custom mods might get wiped out each update or cause unintended effects down the road.
Any reasons why you don't just create a apache admin user with a UID less than 500 so that it won't show in the log in screen as a normal user?
(or simply use a normal user to ssh in before using sudo to become
_www
)?It's a lot less work and more secure.
_www
is intentionally placed in a sandboxbox to reduce the chance that web browsing does bad things to a running mac.