Seeing as nobody else has yet mentioned it, its possible to do this with the pam_access
module.
You'll need to check the pam stack is invoking this module by looking in /etc/pam.d/sshd
and adding as an account
value if it is not there. IE
#%PAM-1.0
auth required pam_sepermit.so
auth substack password-auth
auth include postlogin
account required pam_nologin.so
account required pam_access.so
account include password-auth
password include password-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open env_params
session optional pam_keyinit.so force revoke
session include password-auth
session include postlogin
session required pam_tty_audit.so enable=*
Then, in the access file (default is /etc/security/access.conf
) add the three following lines (providing no other lines offer any other security setup).
+ : bob : 1.2.3.4
- : bob : ALL
+ : ALL : ALL
In SSH
I suppose the following would work.
<Global scope>
DenyUsers bob
Match Address 1.2.3.4
AllowUsers bob