I am trying to restrict a newly added user to his homedir /home/username. Don't want him to be able to cd out of it.

I have this my sshd_config:

Match User username
       ChrootDirectory %h
       X11Forwarding no
       AllowTcpForwarding no
       ForceCommand internal-sftp

I set the owner of /home/username directory to root with chown, and set the permissions to 755.

Also added the user to chroot.conf.

Restarted sshd. But I get a connection closed by remote server when I try to login with the user.


SSH output(edited out some info from it like IP address and RSA key):

OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /Users/Mate/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug1: Connecting to (IP address) [IP address] port 22.
debug1: Connection established.
debug1: identity file /Users/Mate/.ssh/id_rsa type 1
debug1: identity file /Users/Mate/.ssh/id_rsa-cert type -1
debug1: identity file /Users/Mate/.ssh/id_dsa type -1
debug1: identity file /Users/Mate/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
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: Server host key: Some key
debug1: Host 'IP address' is known and matches the RSA host key.
debug1: Found key in /Users/Mate/.ssh/known_hosts:13
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/Mate/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive
debug1: Trying private key: /Users/Mate/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
debug1: Authentication succeeded (keyboard-interactive).
Authenticated to IP address ([IP address]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_CTYPE = UTF-8
debug1: channel 0: free: client-session, nchannels 1
Connection to IP address closed by remote host.
Connection to IP address closed.
Transferred: sent 2400, received 2008 bytes, in 0.2 seconds
Bytes per second: sent 10399.6, received 8701.0
debug1: Exit status -1

Any idea why this happens?

  • 1
    chroot.conf? Try ssh -v username@server.example.net andd add the output to the question
    – ALex_hha
    Sep 5 '13 at 11:53
  • What does the ssh log say?
    – Jenny D
    Sep 5 '13 at 13:56
  • Hi Guys! Thanks for the input. I updated the question with the ssh output.
    – Allanon
    Sep 5 '13 at 16:52

Yes. You've forced him to connect using only the sftp protocol, with ForceCommand internal-sftp. Unsurprisingly, that means he can't ssh in.

  • Hi Madhatter! Thanks for the input but even if I delete ForceCommand internal-sftp the problem is still there.
    – Allanon
    Sep 5 '13 at 16:54
  • And you restarted sshd after the deletion?
    – MadHatter
    Sep 5 '13 at 19:20
  • Yes, I restarted it.
    – Allanon
    Sep 6 '13 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.