LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-23-2010, 11:24 AM   #1
marlon4
LQ Newbie
 
Registered: Apr 2009
Posts: 8

Rep: Reputation: 0
how to prevent same user ssh to the multiple server


Greeting ,

I need some help on how to prevent same user from ssh to multiple linux server at a same time , anyone of you have the script or how to do that ?

Really appreciate it !

Thanks and best regards.

Steve
 
Old 05-23-2010, 12:13 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
MaxSessions in sshd_config can help.
 
Old 05-23-2010, 11:14 PM   #3
marlon4
LQ Newbie
 
Registered: Apr 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by AlucardZero View Post
MaxSessions in sshd_config can help.
Thank you for the reply , but this MaxSessions is applicable for 1 single server ?I need it to cross check betweens servers , so if User A logged in to Server 1 they can't log in to Server 2 .

Thanks
 
Old 05-24-2010, 01:22 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
There's no (built-in) way I know of; why would you want this anyway?
 
Old 05-24-2010, 02:03 AM   #5
marlon4
LQ Newbie
 
Registered: Apr 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
There's no (built-in) way I know of; why would you want this anyway?
I am trying to prevent the same user to log in to multiple server at one time .Is there anyone know came across this problem ?Is there anyway we can make the server to check across servers before allowing the user to log in ?
 
Old 05-24-2010, 02:18 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

I haven't heard of a function like that being build in. In my opinion a minimum requirement in order to have something like this available is to have a centralized authentication system like LDAP. Or you can write a script that checks logged in users on other servers before allowing login, but I imagine that would be quite an undertaking. As asked by chrism01, why would you want this feature? What's the need for it?

Kind regards,

Eric
 
Old 05-24-2010, 02:39 AM   #7
mac.tieu
Member
 
Registered: Jan 2010
Location: Vietnam
Distribution: Arch
Posts: 65

Rep: Reputation: 22
Quote:
Originally Posted by marlon4 View Post
I am trying to prevent the same user to log in to multiple server at one time .Is there anyone know came across this problem ?Is there anyway we can make the server to check across servers before allowing the user to log in ?
You may interested in SSH relay server with OpenSSH

MT.
 
Old 05-24-2010, 05:45 AM   #8
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by marlon4 View Post
Greeting ,

I need some help on how to prevent same user from ssh to multiple linux server at a same time , anyone of you have the script or how to do that ?

Really appreciate it !

Thanks and best regards.

Steve

I believe TCP Wrappers can help you out.
 
Old 05-24-2010, 06:53 AM   #9
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Quote:
Originally Posted by vikas027 View Post
I believe TCP Wrappers can help you out.

Could you be a bit more specific about how TCP wrappers could help the OP's problem? As far as I know, their effect is limited to a single machine.
 
Old 05-26-2010, 02:31 AM   #10
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by Hangdog42 View Post
Could you be a bit more specific about how TCP wrappers could help the OP's problem? As far as I know, their effect is limited to a single machine.
I am sorry, I missed out the "multiple" word in the original post.
 
Old 05-26-2010, 04:30 AM   #11
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Lightbulb

Quote:
Originally Posted by marlon4 View Post
Greeting ,

I need some help on how to prevent same user from ssh to multiple linux server at a same time , anyone of you have the script or how to do that ?

Really appreciate it !

Thanks and best regards.

Steve
Hi,

I have a workaround for this. I am not sure whether this is the best way, But yes it works pretty good. I tested this in RHEL 5.0

For this, I have made a file /tmp/users in which I have entries of the users for which I need to check.
AND
/tmp/check_ssh.sh which is my script.

You just need to run this script in background as
Code:
(bash /tmp/check_ssh.sh &> /dev/null) &
and put usernames of the users in /tmp/users

My files...
Code:
[root@server ~]# cat /tmp/check_ssh.sh
#!/bin/bash
while [ 1 ];
do
for user in `cat /tmp/users`;
do
top -u $user -bn1 | grep -w ssh
if [ $? -eq 0 ]
then
setfacl -m u:$user:000 /usr/bin/ssh
else
setfacl -x u:$user /usr/bin/ssh
fi
done
done;


[root@server ~]# cat /tmp/users  (Here a,b,c are the users)
a
b
c
[root@server ~]#

Now, whenever a user initiates a second ssh session, he gets the below error.
Code:
[a@server ~]$ ssh c@localhost
-bash: /usr/bin/ssh: Permission denied

Just test this, and tell me if you face any issues.
 
Old 05-27-2010, 10:54 AM   #12
marlon4
LQ Newbie
 
Registered: Apr 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by vikas027 View Post
Hi,

I have a workaround for this. I am not sure whether this is the best way, But yes it works pretty good. I tested this in RHEL 5.0

For this, I have made a file /tmp/users in which I have entries of the users for which I need to check.
AND
/tmp/check_ssh.sh which is my script.

You just need to run this script in background as
Code:
(bash /tmp/check_ssh.sh &> /dev/null) &
and put usernames of the users in /tmp/users

My files...
Code:
[root@server ~]# cat /tmp/check_ssh.sh
#!/bin/bash
while [ 1 ];
do
for user in `cat /tmp/users`;
do
top -u $user -bn1 | grep -w ssh
if [ $? -eq 0 ]
then
setfacl -m u:$user:000 /usr/bin/ssh
else
setfacl -x u:$user /usr/bin/ssh
fi
done
done;


[root@server ~]# cat /tmp/users  (Here a,b,c are the users)
a
b
c
[root@server ~]#

Now, whenever a user initiates a second ssh session, he gets the below error.
Code:
[a@server ~]$ ssh c@localhost
-bash: /usr/bin/ssh: Permission denied

Just test this, and tell me if you face any issues.
Sweet , i am going to test this out , may i know to make this applicable for multiple server checking ?If let say i have server A , B , C , how can i make it only to allow User log in to any server at a point of time ?

Really appreciate it .

Thanks
Steve
 
Old 05-27-2010, 12:08 PM   #13
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Thumbs up

Quote:
Originally Posted by marlon4 View Post
If let say i have server A , B , C , how can i make it only to allow User log in to any server at a point of time ?
I have done this only, if a user logs in to server A, he would not be able to login to server B or C, until he logout from server A.

I have tested this code on my machine. Waiting for your response.
 
Old 05-28-2010, 09:59 AM   #14
marlon4
LQ Newbie
 
Registered: Apr 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by vikas027 View Post
I have done this only, if a user logs in to server A, he would not be able to login to server B or C, until he logout from server A.

I have tested this code on my machine. Waiting for your response.
i am sorry , I think i didn't myself clear enough .Your script is good to prevent user ssh to Server B inside Server A .

What i am actually looking for is to stop user from opening a new ssh session to connect to any other servers if they are already connected to anyone .

Really appreciate for your help .

Thanks
Steve
 
Old 05-28-2010, 10:36 AM   #15
bradvan
Member
 
Registered: Mar 2009
Posts: 367

Rep: Reputation: 61
Again, as asked before, why do you need to do this? Maybe if you explained your reasoning, we could come up with a solution.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent certain accounts from being able to SSH to server anon091 Linux - Newbie 10 09-15-2009 05:29 PM
How can i prevent ssh connection for a user epamuk Linux - Server 8 06-11-2009 03:16 PM
How do I prevent a user from being able to log into ssh? scooper Solaris / OpenSolaris 3 04-08-2009 10:50 AM
Prevent a single user from multiple simultaneous logins MichaelP Linux - Networking 6 03-12-2008 10:11 AM
How to prevent root user from logging into ssh linuxjamil Linux - Server 2 10-08-2007 06:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 02:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration