Linux Server - SSH 실습 : 사용자 제한, IP 제한(wrapper)

● 실습 1 - 사용자 제한

1) AllowUsers를 사용해 지정된 유저로 접속
 → 지정된 유저는 접속 가능

2) AllowUsers를 사용해 지정되지 않은 그룹으로 접속
 → 지정되지 않은 그룹은 접속 불가능

3) DenyUsers를 사용해 지정된 유저로 접속
 → 지정된 유저는 접속 불가능

4) DenyUsers를 사용해 지정된 그룹으로 접속
 → 지정되지 않은 그룹은 접속 가능


Server Host는 DNS-Server,
Client Host는 Apache 이다.

- /etc/ssh/sshd_config 파일에 허용 유저/그룹, 거부 유저/그룹 목록을 추가

[root@DNS-Server ~]# vi /etc/ssh/sshd_config
... (생략)
AllowUsers client1 AllowGroups allowG
DenyUsers client2 DenyGroups denyG

→ 입력 후 저장

- 실습에 필요한 유저와 그룹을 생성

[root@DNS-Server ~]# groupadd -g 501 allowG
[root@DNS-Server ~]# groupadd -g 502 denyG
[root@DNS-Server ~]# groupadd -g 503 anotherG
[root@DNS-Server ~]# cat /etc/group
... (생략)
allowG:x:501:
denyG:x:502:
anotherG:x:503:
→ 그룹을 생성

[root@DNS-Server ~]# useradd -g 501 -u 501 client1
[root@DNS-Server ~]# useradd -g 502 -u 502 client2
[root@DNS-Server ~]# useradd -g 503 -u 503 another
[root@DNS-Server ~]# cat /etc/passwd
... (생략)
client1:x:501:501::/home/client1:/bin/bash
client2:x:502:502::/home/client2:/bin/bash
another:x:503:503::/home/another:/bin/bash
→ 유저를 생성

- 유저 계정에 암호 설정
[root@DNS-Server ~]# passwd client1
Changing password for user client1.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@DNS-Server ~]# passwd client2
Changing password for user client2.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@DNS-Server ~]# passwd another
Changing password for user another.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

- sshd 서비스 시작
[root@DNS-Server ~]# service sshd start
sshd (을)를 시작 중:                                       [  OK  ]

1) client1로 접속 시도
client1 : Allow된 유저 계정

[root@Apache ~]# ssh client1@192.168.10.175
The authenticity of host '192.168.10.175 (192.168.10.175)' can't be established.
RSA key fingerprint is 7e:b6:ed:dd:e5:bd:be:99:24:77:23:19:50:8a:fc:f4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.175' (RSA) to the list of known hosts.
client1@192.168.10.175's password:
[client1@DNS-Server ~]$
→ 접속이 정상적으로 된다.

2) anotherG그룹의 유저 another로 접속 시도
anotherG : Allow도 Deny도 되지 않은 그룹

[root@Apache ~]# ssh another@192.168.10.175
another@192.168.10.175's password:
Permission denied, please try again.
→ 접속이 거부된다.

3) denyG 그룹의 유저 client2로 접속 시도

[root@Apache ~]# ssh client2@192.168.10.175
client2@192.168.10.175's password:
Permission denied, please try again.
→ 접속이 거부된다.



● 실습 2 - IP 제한
- Wrapper를 이용해 IP 제한

1) sshd 서비스는 
 hosts.deny 파일을 사용하여 192.168.10.172(클라이언트)를 제외한 모든 접근 막기

- hosts.deny 파일을 수정
[root@DNS-Server ~]# vi /etc/hosts.deny
#
# hosts.deny    This file describes the names of the hosts which are
#               *not* allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!
vsftpd : ALL
sshd : ALL except 192.168.10.172 → 이 부분을 추가

- 허용된 .172 IP 이외의 IP 주소로 접속해보기

- 173번 IP로 접속 시도 (client1 계정)
[root@localhost-173 ~]# ssh client1@192.168.10.175
ssh_exchange_identification: Connection closed by remote host
→ 접속이 불허된다.

댓글

이 블로그의 인기 게시물

Linux Server - FTP 실습 (2 / 2) : 사용자 제한 ( ftpuser / user_list )

전자서명 개념

3.27 (화) - Network (패킷 통신 - 4가지 지연)