Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
SSH deny/allow users per host/ip
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Biffen
n00b
n00b


Joined: 23 Nov 2004
Posts: 32

PostPosted: Fri Feb 18, 2005 9:09 am    Post subject: SSH deny/allow users per host/ip Reply with quote

Hi!

I have a question about ssh (openssh)

Is it possible to deny users login from all ip/hosts but a allow them login from specific ip/host? Or only allow user to access if connecting from specified host.

Here is my example:

Customer1 should have access to only one account, only sftp (using scponly shell). I want to deny them from be able to connect with other users.

On the other side, from my 192.68.0 I want to be able to connect till all accounts, includeing the Customer sftp account.

Regards,

Biffen
Back to top
View user's profile Send private message
seank
l33t
l33t


Joined: 08 Jul 2004
Posts: 686

PostPosted: Fri Feb 18, 2005 10:21 am    Post subject: Reply with quote

Why not just do this with your firewall (you have one, right?)?
Back to top
View user's profile Send private message
cselkirk
Apprentice
Apprentice


Joined: 09 Jun 2003
Posts: 199
Location: NL

PostPosted: Fri Feb 18, 2005 12:06 pm    Post subject: Reply with quote

Your openssh should have support for tcpwrappers (USE="+tcpd" .. which is default). So, you can use tcpwrappers to allow/deny based on hostname/service.

HTH
_________________
cn=cselkirk,dc=xs4all,dc=nl
Back to top
View user's profile Send private message
Paulten
Apprentice
Apprentice


Joined: 28 Mar 2003
Posts: 257
Location: Sykkylven, Norway

PostPosted: Fri Feb 18, 2005 12:50 pm    Post subject: Reply with quote

this may is not as advanced as the thing you describe you want, worth mentioning maybe :

/etc/hosts.allow :

sshd : x.x.x.x : allow
sshd : x.x.x.x : allow
sshd : ALL : deny
_________________
Homepage : http://paul.kde.no Jabber ID : tenfjord@jabber.org
"Dei levde som dyr. Dei verken røykte eller drakk" -Ukjent
Back to top
View user's profile Send private message
nielchiano
Veteran
Veteran


Joined: 11 Nov 2003
Posts: 1287
Location: 50N 3E

PostPosted: Fri Feb 18, 2005 3:16 pm    Post subject: Reply with quote

I'm not sure, but I think he means it like this:

IP 1 should be able to connect to the SSH server, but only be able to login to user 1
IP 2 ..... user 2
IP-range 3 ... ALL users

So not just restrict certain IP's (or restrict all and allow certain), but restrict user/IP-pairs.

I know a way to do it, is by using keys: you can tell in the authorized_keys that the key is only valid from certain IP's...
not sure how to do it with passwords
Back to top
View user's profile Send private message
Biffen
n00b
n00b


Joined: 23 Nov 2004
Posts: 32

PostPosted: Fri Feb 18, 2005 3:49 pm    Post subject: Reply with quote

sean_micken wrote:
Why not just do this with your firewall (you have one, right?)?


Well, I ment deny/allow user login access based on what host connecting from. ;)
Back to top
View user's profile Send private message
Biffen
n00b
n00b


Joined: 23 Nov 2004
Posts: 32

PostPosted: Fri Feb 18, 2005 3:50 pm    Post subject: Reply with quote

cselkirk wrote:
Your openssh should have support for tcpwrappers (USE="+tcpd" .. which is default). So, you can use tcpwrappers to allow/deny based on hostname/service.

HTH


I have looked into that but cant get it right, mabe you know some giudes?
Back to top
View user's profile Send private message
Biffen
n00b
n00b


Joined: 23 Nov 2004
Posts: 32

PostPosted: Fri Feb 18, 2005 3:52 pm    Post subject: Reply with quote

Paulten wrote:
this may is not as advanced as the thing you describe you want, worth mentioning maybe :

/etc/hosts.allow :

sshd : x.x.x.x : allow
sshd : x.x.x.x : allow
sshd : ALL : deny


As I sad, login access based on what host connecting from. :)
Back to top
View user's profile Send private message
Biffen
n00b
n00b


Joined: 23 Nov 2004
Posts: 32

PostPosted: Fri Feb 18, 2005 3:58 pm    Post subject: Reply with quote

nielchiano wrote:
I'm not sure, but I think he means it like this:

IP 1 should be able to connect to the SSH server, but only be able to login to user 1
IP 2 ..... user 2
IP-range 3 ... ALL users

So not just restrict certain IP's (or restrict all and allow certain), but restrict user/IP-pairs.

I know a way to do it, is by using keys: you can tell in the authorized_keys that the key is only valid from certain IP's...
not sure how to do it with passwords


Yes, mabe I was abit unclear when asking ;)

This is what I want to get:

from internet, open fw for 1 host (customer1)
in ssh only allow him to login to specific account (in this case, an only sftp account, using scponly shell)

from my internal network, all hosts have access to any accounts. (or based on hosts connecting from)

---

Ok, mabe its possible if I use authorized_keys? Do you know any guide on this?
Back to top
View user's profile Send private message
spb
Retired Dev
Retired Dev


Joined: 02 Jan 2004
Posts: 2135
Location: Cambridge, UK

PostPosted: Fri Feb 18, 2005 4:49 pm    Post subject: Reply with quote

man sshd_config wrote:
AllowUsers
This keyword can be followed by a list of user name patterns,
separated by spaces. If specified, login is allowed only for
user names that match one of the patterns. `*' and `?' can be
used as wildcards in the patterns. Only user names are valid; a
numerical user ID is not recognized. By default, login is
allowed for all users. If the pattern takes the form USER@HOST
then USER and HOST are separately checked, restricting logins to
particular users from particular hosts.


Looks like it may be helpful.
Back to top
View user's profile Send private message
Biffen
n00b
n00b


Joined: 23 Nov 2004
Posts: 32

PostPosted: Mon Feb 21, 2005 10:30 am    Post subject: Reply with quote

spb wrote:
man sshd_config wrote:
AllowUsers
This keyword can be followed by a list of user name patterns,
separated by spaces. If specified, login is allowed only for
user names that match one of the patterns. `*' and `?' can be
used as wildcards in the patterns. Only user names are valid; a
numerical user ID is not recognized. By default, login is
allowed for all users. If the pattern takes the form USER@HOST
then USER and HOST are separately checked, restricting logins to
particular users from particular hosts.


Looks like it may be helpful.


Yes I tried to get it to work, but I havent had any luck yet. I tried sevral configurations. Login is only possible if not using any hosts.allow/hosts.deny at all or only if host is enterd in hosts.allow. If I try to configure any AllowUsers/DenyUsers sshd just respond to my hosts.allow/hosts.deny configurations (if not using them all users/hosts all allowed to login)

Shuldnt this be working?

hosts.deny
ALL: ALL

hosts.allow
192.168.0.40 192.168.0.50

in sshd_config

AllowUsers myuser@192.168.0.40
DenyUsers myuser@192.168.0.50

myuser is only allowed to login from 192.168.0.40, any other users are allowed from both hosts, no other hosts are allowed at all.

- - -

If I try login, both hosts is allowed to log in as myuser. :/
Back to top
View user's profile Send private message
gcasillo
l33t
l33t


Joined: 23 Sep 2003
Posts: 739
Location: Cincinnati, Ohio, USA

PostPosted: Tue Mar 01, 2005 9:42 pm    Post subject: Reply with quote

Just a friendly reminder to those using the "AllowUsers" syntax in their sshd_config files: remember to prepend the username to the IP address. Otherwise, nobody gets in. :oops:

So can I use a wildcard with AllowUsers to allow _all_ users from a range of IP addresses? For example:
Code:
AllowUsers *@192.168.0.*

Will that work I wonder?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum