LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-26-2017, 02:44 AM   #1
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
sshd: invalid DenyUsers pattern


I want to block external access via ssh for a particular user, and this works with:
Code:
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
On:
Code:
CentOS release 6.9 (Final)
Excerpt from sshd_config:
Code:
# Deny this user if not from this host
DenyUsers foobar@!192.168.26.128,
The above works perfectly. User foobar can only log in from 192.168.26.128 and not from anywhere else.

However, when trying to implement this with:
Code:
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
On:
Code:
Red Hat Enterprise Linux Server release 7.4 (Maipo)
I get this error message:
Code:
/etc/ssh/sshd_config line 89: invalid DenyUsers pattern: "foobar@!192.168.26.128,"
Excerpt form sshd_config:
Code:
DenyUsers foobar@!192.168.26.128,
This is extremely annoying, and I have not found any info on what has changed in the different versions. Any help would be appreciated!

Best regards,
HMW
 
Old 10-26-2017, 03:36 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
USER and HOST are supposed to be checked separately and since patterns can be used, and they used to work, they should still work in the newer versions for HOST:
" DenyUsers
This keyword can be followed by a list of user name patterns, separated by spaces. Login is disallowed for user names that match one of 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. HOST criteria may additionally contain addresses to match in CIDR address/masklen format. The allow/deny directives are processed in the following order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups.

See PATTERNS in ssh_config(5) for more information on patterns."
I'd say it's probably a bug. Report it for your distro.
 
Old 10-26-2017, 03:40 AM   #3
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773

Original Poster
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by Turbocapitalist View Post
USER and HOST are supposed to be checked separately and since patterns can be used, and they used to work, they should still work in the newer versions for HOST:
" DenyUsers
This keyword can be followed by a list of user name patterns, separated by spaces. Login is disallowed for user names that match one of 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. HOST criteria may additionally contain addresses to match in CIDR address/masklen format. The allow/deny directives are processed in the following order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups.

See PATTERNS in ssh_config(5) for more information on patterns."
I'd say it's probably a bug. Report it for your distro.
Thanks for your reply. Unfortunately I tested this on Debian 9, and the bug is there too. So it's not distro-specific. Negation simply does not seem to work well with openSSH?
 
Old 10-26-2017, 04:09 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
Quote:
Originally Posted by HMW View Post
Unfortunately I tested this on Debian 9, and the bug is there too. So it's not distro-specific.
Then it might be a regression upstream. Did the release notes between now and the last version that worked have any mention of changing how patterns are done with DenyUsers?

http://www.openssh.com/txt/

Edit: I found nothing direct but there were two changes that might be related.

http://www.openssh.com/txt/release-7.4
http://www.openssh.com/txt/release-6.1

Last edited by Turbocapitalist; 10-26-2017 at 04:14 AM.
 
Old 10-26-2017, 04:24 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,768

Rep: Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933Reputation: 5933
Looks like a bug that has not been fixed yet?

https://bugzilla.mindrot.org/show_bug.cgi?id=2397

Last edited by michaelk; 10-26-2017 at 04:27 AM.
 
1 members found this post helpful.
Old 10-26-2017, 05:18 AM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773

Original Poster
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Thank you both for your replies. Yes, it seems that this is indeed a bug.
This:
Quote:
To calibrate expectations, there's little chance all of these are going to make 7.6.
..was not very comforting. I will have to try and implement a solution that does not require negation for now - even though it will make it more cumbersome.
 
Old 10-26-2017, 11:23 AM   #7
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773

Original Poster
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
If anyone finds this post, the solution is to use this syntax:
Code:
DenyUsers localuser@*,!10.8.0.*
When implementing on recent versions of openSSH.

Ergo; this:
Code:
DenyUsers foobar@!192.168.26.128,
...on legacy versions of openSSH

Becomes this:
Code:
DenyUsers foobar@*,!192.168.26.128
...on current versions of openSSH
 
2 members found this post helpful.
  


Reply

Tags
redhat, sshd_config



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
[SOLVED] invalid initialization of non-const reference of type ‘std::money_base::pattern&' fsshl Programming 2 03-26-2015 08:15 AM
Locked Out of SSH Due to Invalid SSHD Config DeltaCharlieBravo Linux - Security 3 11-01-2013 01:08 PM
[SOLVED] /bin/bash if statement pattern search, end of pattern special character? headhunter_unit23 Programming 3 04-29-2010 08:05 AM
Starting sshd: /etc/init.d/sshd: line 113: /usr/sbin/sshd: Permission denied sumanc Linux - Server 5 03-28-2008 04:59 AM
How to deal with SSHD invalid user XXXX from www.xxx.yyy.xxx 1kyle SUSE / openSUSE 1 09-30-2006 05:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:51 AM.

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