2

I made the changes in /etc/security/limits.conf

test        hard    maxlogins       2
sftptest    hard    maxlogins       2
  • After above entries I have tested below scenarios

    1. Open 2 putty sessions when I tried to open 3rd sessions it disconnect automatically (Working fine with ssh user not for sftp user )
    2. Open 2 putty sessions when I am trying to open 3rd session from the filezilla / winscp connection disconnected automatically (Working fine with ssh user ) 3.When I am trying to open 3 sessions in filezilla/winscp I am able to open 3 sessions ( Not working)
    3. when I am trying to open 3 sessions in filezilla/winscp with sftp users I am able to open all three sessions -Is there any difference in putty client and winscp/filezilla ? -SSH users having shell login but sftp users don't have shell login
  • Is there any chance to limit the connections 2 for sftp users?

I am pretty new to Linux.

  • 1
    Two options using MaxSession or firewall. The first will work if your ssh supports it! – George Udosen Jan 12 '18 at 4:36
  • Can you please let me know how to do it from firewall side ? – Trivedh Jan 12 '18 at 4:45
  • 1
    Try this rule: sudo firewall-cmd --permanent --direct --add-rule iptables -I INPUT -p TCP --dport 22 --syn -m connlimit --connlimit-above 2 -j REJECT, this only limits per ip not per user! – George Udosen Jan 12 '18 at 6:03
  • Thanks for the reply , but i am looking for user side . – Trivedh Jan 12 '18 at 6:11
0

You can limit the process count for that user. During a scp, 3 processes are created with root, sshd and sftptest(in your case) users.
So you can limit the max process count for that user in /etc/security/limits.conf

sftptest hard nproc 2

This is not a very efficient way because you block the connection after it is authenticated.

| improve this answer | |
-2

I am not sure that it is possible to achieve exactly what you desire, at least not by simply setting configuration variables for existing tools.

The next best option might be to use the MaxSessions option in sshd_config. This:

Specifies the maximum number of open shell, login or subsystem (e.g. sftp) sessions permitted per network connection. Multiple sessions may be established by clients that support connection multiplexing. Setting MaxSessions to 1 will effectively disable session multiplexing, whereas setting it to 0 will prevent all shell, login and subsystem sessions while still permitting forwarding. The default is 10.

If you wish to do that, then in /etc/ssh/sshd_config, look for the a line with the text MaxSessions. Edit it to read as follows:

MaxSessions 2

Then save the file and restart the SSH daemon.

| improve this answer | |
  • Hi , I already did the same . Through putty client it is taking two connections only . But when l logged in as a sftp user it is taking 5+ connections at a time . – Trivedh Jan 12 '18 at 4:44
  • 1
    Are you sure that those sftp connections are distinct sessions? – sampablokuper Jan 12 '18 at 4:52
  • Yes , I logged in from three different machines through winscp/filezilla . – Trivedh Jan 12 '18 at 5:28
  • 1
    @Trivedh, not sure I can help, but out of curiosity: were those three client machines sharing an IP address, and was the server on a different IP address to all of the clients? – sampablokuper Jan 12 '18 at 6:22
  • 1
    The sshd MaxSessions option doesn't actually do what the OP wants to do. It just limits the number of multiplexed streams per TCP connection. – Kenster Jan 30 '18 at 17:54

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.