SSH auf bestimmte IPs für bestimmte User

N

Navigato

Grünschnabel
Hallo zusammen,

ich möchte auf einem CentOS7 für bestimmte OS-Benutzer den Zugriff per SSH nur auf bestimmte IP's erlauben. Ich habe aber kim Moment keine schlaue Idee wie man das umsetzen könnte:

Beispiel:
user1 -> 1.2.3.4 und 2.3.4.9 und 3.4.5.0/24, sonst nichts
user2 -> 5.6.7.8 und 1.2.3.4 , sonst nichts

Ist das überhaupt möglich? Ich habe da an die Firewall gedacht, dass die das evtl. kann, aber ich habe noch keine Möglichkeit gefunden wie ich den User da noch filtern kann.

Danke & Gruß
Navigato
 
Zuletzt bearbeitet:
Mit einem Match-Block in der sshd_config kann man das umsetzen.

Auszug aus der sshd_config manpage:

Code:
     Match   Introduces a conditional block.  If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the con-
             fig file, until either another Match line or the end of the file.  If a keyword appears in multiple Match blocks that are satisfied, only the first instance of the keyword is
             applied.

             The arguments to Match are one or more criteria-pattern pairs or the single token All which matches all criteria.  The available criteria are User, Group, Host, LocalAddress,
             LocalPort, and Address.  The match patterns may consist of single entries or comma-separated lists and may use the wildcard and negation operators described in the PATTERNS sec-
             tion of ssh_config(5).

             The patterns in an Address criteria may additionally contain addresses to match in CIDR address/masklen format, such as 192.0.2.0/24 or 2001:db8::/32.  Note that the mask length
             provided must be consistent with the address - it is an error to specify a mask length that is too long for the address or one with bits set in this host portion of the address.
             For example, 192.0.2.0/33 and 192.0.2.0/8, respectively.

             Only a subset of keywords may be used on the lines following a Match keyword.  Available keywords are AcceptEnv, AllowAgentForwarding, AllowGroups, AllowStreamLocalForwarding,
             AllowTcpForwarding, AllowUsers, AuthenticationMethods, AuthorizedKeysCommand, AuthorizedKeysCommandUser, AuthorizedKeysFile, AuthorizedPrincipalsCommand,
             AuthorizedPrincipalsCommandUser, AuthorizedPrincipalsFile, Banner, ChrootDirectory, ClientAliveCountMax, ClientAliveInterval, DenyGroups, DenyUsers, ForceCommand, GatewayPorts,
             GSSAPIAuthentication, HostbasedAcceptedKeyTypes, HostbasedAuthentication, HostbasedUsesNameFromPacketOnly, IPQoS, KbdInteractiveAuthentication, KerberosAuthentication,
             MaxAuthTries, MaxSessions, PasswordAuthentication, PermitEmptyPasswords, PermitOpen, PermitRootLogin, PermitTTY, PermitTunnel, PermitUserRC, PubkeyAcceptedKeyTypes,
             PubkeyAuthentication, RekeyLimit, RevokedKeys, StreamLocalBindMask, StreamLocalBindUnlink, TrustedUserCAKeys, X11DisplayOffset, X11Forwarding and X11UseLocalHost.

Vielleicht hilft diese englische Seite auch:

https://www.cyberciti.biz/faq/match...-root-loginfrom-one_ip_address-on-linux-unix/
 
Es lässt sich auch mit firewalld lösen.
 

Ähnliche Themen

chroot für bestimmte ssh-keys

Problem mit Apache2 + MySQL Server

(Zugriffs-)Rechte für Apache-Vhost-user. Wieviel ist gut?

Zurück
Oben