Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Restricted SFTP Access
PostPosted: Thu Nov 04, 2010 9:33 am 
Offline
Senior Newbie

Joined: Thu Oct 28, 2010 7:35 pm
Posts: 17
Website: http://devaldez.com
Location: brooklyn
hey all,

i want to restrict a users of a certain group to their home directories.

i've tried the following in sshd_config

Code:
Subsystem sftp internal-sftp

Match group filetransfer
    ChrootDirectory %h
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp


And the following commands:

Code:
usermod -G filetransfer username
chown root:root /home/username
chmod 755 /home/username

cd /home/username
mkdir docs public_html
chown username:username *


But after restarting ssh the user could not log in at all


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 10:02 am 
Offline
Senior Member

Joined: Mon Jul 05, 2010 5:13 pm
Posts: 392
Do you use PasswordAuthentication?

If PasswordAuthentication is off above, you either need to add a "PasswordAuthentication on" line to your match section, or add the .ssh/authorized_keys file to your sftp jail.


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 10:03 am 
Offline
Senior Newbie

Joined: Thu Oct 28, 2010 7:35 pm
Posts: 17
Website: http://devaldez.com
Location: brooklyn
yes,

Code:
PasswordAuthentication yes


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 11:14 am 
Offline
Senior Member

Joined: Mon Jul 05, 2010 5:13 pm
Posts: 392
What error are you getting when you try to ssh in? I'd recommend logging in with the -v flag (ssh -v), and also checking any errors in /var/log/auth.log on your server.

I'll add that you probably want to strongly consider setting up pubkey authentication for your server. It's really not that much harder than password auth to setup, and the gains in security are considerable.

I personally use pubkey for my shell logins, and password for sftp jails.


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 11:28 am 
Offline
Senior Newbie

Joined: Thu Oct 28, 2010 7:35 pm
Posts: 17
Website: http://devaldez.com
Location: brooklyn
i actually want this user to only be able to sftp so, im not sure if this matters but...

ssh -v provides the following:

Code:
$ ssh -v chris@domain.com

OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to domain.com [111.111.111.111] port 22.
debug1: Connection established.
debug1: identity file /Users/matt/.ssh/identity type -1
debug1: identity file /Users/matt/.ssh/id_rsa type 1
debug1: identity file /Users/matt/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-3ubuntu4
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'domain.com' is known and matches the RSA host key.
debug1: Found key in /Users/matt/.ssh/known_hosts:14
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/matt/.ssh/identity
debug1: Offering public key: /Users/matt/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/matt/.ssh/id_dsa
debug1: Next authentication method: password
chris@domain.com's password:



but you can see the identity file is coming from user "matt" when "chris" is trying to log in. is that expected?

after entering the pw (i'm sure it's correct because it works with the match disabled) i get this error in auth.log

Code:
Nov  4 15:21:48 localhost sshd[21514]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=cpe-11-11-11-111.nyc.res.rr.com  user=chris
Nov  4 15:21:51 localhost sshd[21514]: Failed password for chris from 11.11.11.111 port 43647 ssh2


sftp just error is failed password too.


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 1:16 pm 
Offline
Senior Member

Joined: Mon Jul 05, 2010 5:13 pm
Posts: 392
It says Matt because that's who you're logged onto your computer as. It's checking your local home folder for public keys.

From what I'm seeing, if you're sure you've got the right pass, it should work.


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 2:02 pm 
Offline
Senior Newbie

Joined: Thu Oct 28, 2010 7:35 pm
Posts: 17
Website: http://devaldez.com
Location: brooklyn
this is what happens after the pw is entered:

Code:
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: channel 0: free: client-session, nchannels 1
Read from remote host domain.com: Connection reset by peer
Connection to domain.com closed.
Transferred: sent 1632, received 1800 bytes, in 0.1 seconds
Bytes per second: sent 31776.9, received 35048.1
debug1: Exit status -1


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 5:23 pm 
Offline

Joined: Thu Nov 04, 2010 4:58 pm
Posts: 1
Do you have a white/black list in your sshd_config (i.e. AllowUsers etc)? That might cause some of those messages you listed above.


Top
   
 Post subject:
PostPosted: Thu Nov 04, 2010 8:45 pm 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Try setting your servers log level to debug in sshd_config then check /var/log/auth.log it might provide more clues.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Sat Nov 06, 2010 12:08 pm 
Offline
Senior Newbie

Joined: Thu Oct 28, 2010 7:35 pm
Posts: 17
Website: http://devaldez.com
Location: brooklyn
i'm not sure why, but after rebooting the linode it works!

this lead me to the next issue.

i wanted a user to have access to a folder outside of his home directory.

i looked into symlinks but it seems that that's the wrong utility for this situation.

so i used

Code:
mount -o bind /outside /home/user/outside


this does the trick! but i'm unsure about how to make this persistant.

i added this to /etc/fstab but i'm not sure if that was the right move, although it seems to work.

Code:
/srv/www/shared /home/chris/shared none bind


now, if anyuser tries to download a handful of files via sftp port 22 timesout and closes.

i'm not sure how to to even begin debugging this issue, so any help would be appreciated.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: sjnorton and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group