Remote Service 3(④remoSvc2(openssh) ⑤remoSvc3(scp))
* 강사님 정리 노트 :
* vnc(Virtual Network Computing)
vnc(Virtual Network Computing)
- 오픈 소스인 vnc는 Windows Server에서 Terminal Service와 비슷한 기능을 가지고 있음
cf) windows에선 terminal service라고 부름
- 플랫폼(운영체제)을 가리지 않음
- 설치가 간편함
- CLI 환경이 아니라 GUI 환경을 제공함
-RFB(Remote Frame Buffer protocol)
프레임 버퍼 레벨에서 동작함
OS와 상관없이 모든 OS에서 프레임 단위로 통신
원격으로 다른 컴퓨터를 제어하고 키보드와 마우스를 입력하면 그대로 전달이 됨
작업 전에
tigervnc 패키지 유무를 확인!
tigervnc로 시작하는 패키지를 설치해야 함
패키지 설치 후
vncserver@.service(데몬)을 재시작해야하지만 설정을 하지 않았기 때문에 실패
(참고로 CentOS 7 이전에는
/etc/sysconfig/vncservers 파일에서 작업.
CentOS 7 에서는 /usr/lib/systemd/system/vncserver@.service를 복사해서 사용함)
vncserver(명령어)
vncserver 명령 시 로그인 한 사용자 계정의 홈 디렉터리 하위에 .vnc 디렉터리가 자동생성
그리고 .vnc 디렉터리 하위에 여러 파일들이 저장되어 있음
.vnc 디렉터리 하위에 파일들
config
→ 해상도, 공유, 데스크탑 등 관련 설정 파일
passwd
→ vnc 접속 시 이용하여 해당 사용자 계정으로 접속할 때 비밀번호가 저장되어 있는 파일
(참고로 vnc 접속할 때 비밀번호를 잃어버렸을 경우 vncpasswd(명령어)를 이용하여 해결할 수 있음)
xstartup
→ vncserver의 스크립트 파일
hostname: 세션번호.log
→ vnc 접속 시 관련 기록이 저장되어지는 파일
hostname: 세션번호.pid
→ vnc 접속 시 사용할 프로세스 아이디가 저장되어 있는 파일
# cat /root/.vnc/xstartup
(참고로
CentOS 5.x 에서는 4줄과 5줄에 맨 앞에 '#'(주석)을 제거한 다음에 사용해야 함
CentOS 6.x 에서는 7줄과 21줄에 맨 앞에 '#'이 없으므로 설정할 필요가 없음
CentOS 7.x 에서는 3줄과 5줄에 맨 앞에 '#'이 없으므로 설정할 필요가 없음
vncserver 접속 방법
1) vncviewer(명령어) 입력 후 enter
VNC Viewer 창이 뜸
옵션, 로드, 저장, 접속 등이 있으므로 설정할 수 있음
VNC server : 에 Server-IP:세션번호 을 적음 → Connect
VNC authentication이 뜨고 Password: 비밀번호를 입력 → OK
192.168.46.90:1
2) vncviewer Service-IP:세션번호
vncserver 접속 해제
1) 현재 열려있는 세션 종료
사용형식
vncserver -kill :세션번호
// 2018.01.19
현재 동작중인 서비스 종료
killall
- 프로세스의 이름으로 프로세스를 종료
사용형식
killall [option] 서비스 (daemon)
외부에서 vncviewer 접속
[서버] 에서만
// vnc package 설치
[root@junga ~]# rpm -qa | grep tigervnc*
tigervnc-server-minimal-1.8.0-1.el7.x86_64
tigervnc-license-1.8.0-1.el7.noarch
[root@junga ~]#
[root@junga ~]# rpm -qa | grep openssh*
openssh-clients-7.4p1-12.el7_4.x86_64
openssl-libs-1.0.2k-8.el7.x86_64
openssh-server-7.4p1-12.el7_4.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
openssl-1.0.2k-8.el7.x86_64
openssh-7.4p1-12.el7_4.x86_64
[root@junga ~]#
[root@junga ~]# yum -y install tigervnc*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.daumkakao.com
* extras: data.nicehosting.co.kr
* updates: mirror.navercorp.com
Resolving Dependencies
--> Running transaction check
---> Package tigervnc.x86_64 0:1.8.0-2.el7_4 will be installed
--> Processing Dependency: libfltk_images.so.1.3()(64bit) for package: tigervnc-1.8.0-2.el7_4.x86_64
--> Processing Dependency: libfltk.so.1.3()(64bit) for package: tigervnc-1.8.0-2.el7_4.x86_64
---> Package tigervnc-icons.noarch 0:1.8.0-2.el7_4 will be installed
---> Package tigervnc-license.noarch 0:1.8.0-1.el7 will be updated
---> Package tigervnc-license.noarch 0:1.8.0-2.el7_4 will be an update
---> Package tigervnc-server.x86_64 0:1.8.0-2.el7_4 will be installed
---> Package tigervnc-server-applet.noarch 0:1.8.0-2.el7_4 will be installed
---> Package tigervnc-server-minimal.x86_64 0:1.8.0-1.el7 will be updated
---> Package tigervnc-server-minimal.x86_64 0:1.8.0-2.el7_4 will be an update
---> Package tigervnc-server-module.x86_64 0:1.8.0-2.el7_4 will be installed
--> Running transaction check
---> Package fltk.x86_64 0:1.3.4-1.el7 will be installed
--> Processing Dependency: libGLU.so.1()(64bit) for package: fltk-1.3.4-1.el7.x86_64
--> Running transaction check
---> Package mesa-libGLU.x86_64 0:9.0.0-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
tigervnc x86_64 1.8.0-2.el7_4 updates 239 k
tigervnc-icons noarch 1.8.0-2.el7_4 updates 37 k
tigervnc-server x86_64 1.8.0-2.el7_4 updates 213 k
tigervnc-server-applet noarch 1.8.0-2.el7_4 updates 566 k
tigervnc-server-module x86_64 1.8.0-2.el7_4 updates 216 k
Updating:
tigervnc-license noarch 1.8.0-2.el7_4 updates 28 k
tigervnc-server-minimal x86_64 1.8.0-2.el7_4 updates 1.0 M
Installing for dependencies:
fltk x86_64 1.3.4-1.el7 base 560 k
mesa-libGLU x86_64 9.0.0-4.el7 base 196 k
Transaction Summary
============================================================================================
Install 5 Packages (+2 Dependent packages)
Upgrade 2 Packages
Total size: 3.1 M
Total download size: 2.0 M
Downloading packages:
(1/7): tigervnc-icons-1.8.0-2.el7_4.noarch.rpm | 37 kB 00:00:00
(2/7): tigervnc-1.8.0-2.el7_4.x86_64.rpm | 239 kB 00:00:00
(3/7): mesa-libGLU-9.0.0-4.el7.x86_64.rpm | 196 kB 00:00:00
(4/7): fltk-1.3.4-1.el7.x86_64.rpm | 560 kB 00:00:01
(5/7): tigervnc-server-1.8.0-2.el7_4.x86_64.rpm | 213 kB 00:00:00
(6/7): tigervnc-server-module-1.8.0-2.el7_4.x86_64.rpm | 216 kB 00:00:00
(7/7): tigervnc-server-applet-1.8.0-2.el7_4.noarch.rpm | 566 kB 00:00:00
--------------------------------------------------------------------------------------------
Total 1.4 MB/s | 2.0 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Updating : tigervnc-license-1.8.0-2.el7_4.noarch 1/11
Updating : tigervnc-server-minimal-1.8.0-2.el7_4.x86_64 2/11
Installing : tigervnc-server-1.8.0-2.el7_4.x86_64 3/11
Installing : mesa-libGLU-9.0.0-4.el7.x86_64 4/11
Installing : fltk-1.3.4-1.el7.x86_64 5/11
Installing : tigervnc-icons-1.8.0-2.el7_4.noarch 6/11
Installing : tigervnc-1.8.0-2.el7_4.x86_64 7/11
Installing : tigervnc-server-applet-1.8.0-2.el7_4.noarch 8/11
Installing : tigervnc-server-module-1.8.0-2.el7_4.x86_64 9/11
Cleanup : tigervnc-server-minimal-1.8.0-1.el7.x86_64 10/11
Cleanup : tigervnc-license-1.8.0-1.el7.noarch 11/11
Verifying : tigervnc-server-1.8.0-2.el7_4.x86_64 1/11
Verifying : tigervnc-icons-1.8.0-2.el7_4.noarch 2/11
Verifying : tigervnc-server-module-1.8.0-2.el7_4.x86_64 3/11
Verifying : tigervnc-1.8.0-2.el7_4.x86_64 4/11
Verifying : tigervnc-server-minimal-1.8.0-2.el7_4.x86_64 5/11
Verifying : fltk-1.3.4-1.el7.x86_64 6/11
Verifying : tigervnc-license-1.8.0-2.el7_4.noarch 7/11
Verifying : tigervnc-server-applet-1.8.0-2.el7_4.noarch 8/11
Verifying : mesa-libGLU-9.0.0-4.el7.x86_64 9/11
Verifying : tigervnc-server-minimal-1.8.0-1.el7.x86_64 10/11
Verifying : tigervnc-license-1.8.0-1.el7.noarch 11/11
Installed:
tigervnc.x86_64 0:1.8.0-2.el7_4
tigervnc-icons.noarch 0:1.8.0-2.el7_4
tigervnc-server.x86_64 0:1.8.0-2.el7_4
tigervnc-server-applet.noarch 0:1.8.0-2.el7_4
tigervnc-server-module.x86_64 0:1.8.0-2.el7_4
Dependency Installed:
fltk.x86_64 0:1.3.4-1.el7 mesa-libGLU.x86_64 0:9.0.0-4.el7
Updated:
tigervnc-license.noarch 0:1.8.0-2.el7_4 tigervnc-server-minimal.x86_64 0:1.8.0-2.el7_4
Complete!
[root@junga ~]#
[root@junga ~]# rpm -qa | grep tigervnc | nl
1 tigervnc-server-1.8.0-2.el7_4.x86_64
2 tigervnc-server-applet-1.8.0-2.el7_4.noarch
3 tigervnc-license-1.8.0-2.el7_4.noarch
4 tigervnc-server-module-1.8.0-2.el7_4.x86_64
5 tigervnc-server-minimal-1.8.0-2.el7_4.x86_64
6 tigervnc-icons-1.8.0-2.el7_4.noarch
7 tigervnc-1.8.0-2.el7_4.x86_64
[root@junga ~]#
[root@junga ~]# ls -l /usr/lib/systemd/system/vncserver@.service
-rw-r--r-- 1 root root 1679 12월 2 08:22 /usr/lib/systemd/system/vncserver@.service
[root@junga ~]#
[root@junga ~]# ls -l /etc/sysconfig/vncservers
-rw-r--r-- 1 root root 72 12월 2 08:22 /etc/sysconfig/vncservers
[root@junga ~]#
[root@junga ~]# cat /etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service
// vncserver
[root@junga ~]# vncserver
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
New 'junga.kgitbank:1 (root)' desktop is junga.kgitbank:1
Creating default startup script /root/.vnc/xstartup
Creating default config /root/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/junga.kgitbank:1.log
[root@junga ~]# ls -l /root/.vnc
합계 20
-rw-r--r-- 1 root root 332 1월 18 14:48 config
-rw-r--r-- 1 root root 750 1월 18 14:51 junga.kgitbank:1.log
-rw-r--r-- 1 root root 5 1월 18 14:48 junga.kgitbank:1.pid
-rw------- 1 root root 8 1월 18 14:48 passwd
-rwxr-xr-x 1 root root 92 1월 18 14:48 xstartup
[root@junga ~]#
[root@junga ~]# cat /root/.vnc/junga.kgitbank\:1.pid
4834
[root@junga ~]# cat /root/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec /etc/X11/xinit/xinitrc
// vncviewer 실행
[root@junga ~]# vncviewer
TigerVNC Viewer 64-bit v1.8.0
Built on: 2017-12-01 23:20
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Thu Jan 18 15:05:58 2018
DecodeManager: Detected 1 CPU core(s)
DecodeManager: Decoding data on main thread
CConn: connected to host 192.168.46.90 port 5901
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
CConnection: Choosing security type VeNCrypt(19)
CVeNCrypt: Choosing security type TLSVnc (258)
Thu Jan 18 15:06:02 2018
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using Tight encoding
CConn: Enabling continuous updates
// 192.168.46.90:1
Thu Jan 18 15:12:25 2018
CConn: read: 연결이 상대편에 의해 끊어짐 (104)
[root@junga ~]#
// vncserver 종료
[root@junga ~]# vncserver -kill :1
Killing Xvnc process ID 4834
Xvnc seems to be deadlocked. Kill the process manually and then re-run
/usr/bin/vncserver -kill :1
to clean up the socket files.
[root@junga ~]#
// vncviewer 재 접속
[root@junga ~]# vncviewer 192.168.46.90:1
TigerVNC Viewer 64-bit v1.8.0
Built on: 2017-12-01 23:20
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Thu Jan 18 15:14:35 2018
DecodeManager: Detected 1 CPU core(s)
DecodeManager: Decoding data on main thread
CConn: connected to host 192.168.46.90 port 5901
Thu Jan 18 15:14:36 2018
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
CConnection: Choosing security type VeNCrypt(19)
CVeNCrypt: Choosing security type TLSVnc (258)
Thu Jan 18 15:14:42 2018
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using Tight encoding
CConn: Enabling continuous updates
// 2018.01.19 실습
[root@junga ~]# vncviewer
TigerVNC Viewer 64-bit v1.8.0
Built on: 2017-12-01 23:20
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Fri Jan 19 12:51:37 2018
DecodeManager: Detected 1 CPU core(s)
DecodeManager: Decoding data on main thread
CConn: unable connect to socket: 연결이 거부됨 (111)
[root@junga ~]# vncserver
Warning: junga.kgitbank:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server junga.kgitbank:1
New 'junga.kgitbank:2 (root)' desktop is junga.kgitbank:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/junga.kgitbank:2.log
[root@junga ~]# vncviewer
TigerVNC Viewer 64-bit v1.8.0
Built on: 2017-12-01 23:20
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Fri Jan 19 12:53:37 2018
DecodeManager: Detected 1 CPU core(s)
DecodeManager: Decoding data on main thread
CConn: connected to host 192.168.46.90 port 5902
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
CConnection: Choosing security type VeNCrypt(19)
CVeNCrypt: Choosing security type TLSVnc (258)
Fri Jan 19 12:53:47 2018
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using Tight encoding
CConn: Enabling continuous updates
Fri Jan 19 12:56:06 2018
CConn: End of stream
[root@junga ~]#
* sftp(Secure FTP) ← Service 4>
sftp(Secure FTP)
- 일반적인 ftp service는 암호화 통신을 하지 않으므로 서비스 이용시 안정성을 보장 받을 수 없음
- ssh service에 내장되어 있는 sftp는 안전하게 파일을 업로드, 다운로드 할 수 있음
사용형식
sftp 계정명@Server-IP
upload는 put
download는 get
[서버]
[root@junga ~]# mkdir /test/sftp
mkdir: `/test/sftp' 디렉토리를 만들 수 없습니다: 파일이 있습니다
[root@junga ~]#
[root@junga ~]# ls -l /test/sftp/
합계 0
[root@junga ~]#
[root@junga ~]# touch /test/sftp/testfile3
[root@junga ~]#
[root@junga ~]# ls -l /test/sftp/
합계 0
-rw-r--r-- 1 root root 0 1월 18 14:13 testfile3
[root@junga ~]#
[root@junga ~]#
[클라이언트] get 가져오기 (download)
[junga@localhost tmp]$ touch /tmp/testfile2
[junga@localhost tmp]$
[junga@localhost tmp]$ ls -l /tmp/testfile2
-rw-rw-r-- 1 junga junga 0 1월 18 14:15 /tmp/testfile2
[junga@localhost tmp]$
[junga@localhost tmp]$
[junga@localhost tmp]$ sftp itbank@192.168.46.90
Hello sshd Service~!
itbank@192.168.46.90's password:
Connected to 192.168.46.90.
sftp>
sftp> pwd
Remote working directory: /home/itbank
sftp>
sftp> cd /test/sftp
sftp>
sftp> get testfile3 // 서버 pc 기준. 서버에서 가져오므로 (경로 안썼기 때문에 다시 해볼것!)
Fetching /test/sftp/testfile3 to testfile3
sftp>
sftp> quit
[클라이언트] upload 주기 (put)
192.168.46.90's password:
Connected to 192.168.46.90.
sftp> pwd
Remote working directory: /home/itbank
sftp>
sftp> cd /test/sftp/
sftp>
sftp> pwd
Remote working directory: /test/sftp
sftp>
sftp> put /tmp/testfi
testfile1 testfile2 testfile3 testfile4
sftp> put /tmp/testfile2
Uploading /tmp/testfile2 to /test/sftp/testfile2
remote open("/test/sftp/testfile2"): Permission denied
sftp>
sftp> quit
[서버]
[root@junga ~]# ls -ld /test/sftp
drwxr-xr-x 2 root root 23 1월 18 14:13 /test/sftp
[root@junga ~]#
[root@junga ~]# chmod 757 /test/sftp
[root@junga ~]#
[root@junga ~]# ls -ld /test/sftp
drwxr-xrwx 2 root root 23 1월 18 14:13 /test/sftp
[root@junga ~]#
[root@junga ~]# ls -l /test/sftp
합계 0
-rw-rw-r-- 1 itbank itbank 0 1월 18 14:23 testfile2
-rw-r--r-- 1 root root 0 1월 18 14:13 testfile3
[root@junga ~]#
[root@junga ~]#
[클라이언트]
sftp> put /tmp/testfile2
Uploading /tmp/testfile2 to /test/sftp/testfile2
/tmp/testfile2 100% 0 0.0KB/s 00:00
sftp>
* scp(Secure CoPy)← Service 1_3>
- ssh service가 구성되어있는 시스템을 대상으로 원격 복사할 수 있는 기능
- 일반적인 cp는 암호화통신을 하지 않으므로 보안상 좋지 않음
- openssh-clients 패키지에 내장되어 있음
사용형식(복사 해오기)
scp [option] 계정명@Server-IP:원본파일 사본파일
사용형식(복사 해주기)
scp [option] 원본파일 계정명@Server-IP:사본파일
// 실습
// 복사 해오기
<서버>
[root@junga ~]# ls -ld /test/scp
drwxr-xr-x 2 root root 23 1월 18 13:18 /test/scp // itbank는 other
<클라이언트>
[junga@localhost tmp]$ ls -ld /tmp/
drwxrwxrwt. 37 root root 4096 1월 18 13:49 /tmp/ // sticky bit, 공용디렉터리 other
[junga@localhost ~]$ cd /tmp/
[junga@localhost tmp]$ scp itbank@192.168.46.90:/test/scp/testfile4 testfile4
[junga@localhost tmp]$ scp itbank@192.168.46.90:/test/scp/testfile4 /tmp
Hello sshd Service~!
itbank@192.168.46.90's password:
testfile4 100% 0 0.0KB/s 00:00
[junga@localhost tmp]$
[junga@localhost tmp]$ ls
systemd-private-aa1648d0817f4e79870de1a84a0e26d0-vmtoolsd.service-PCQVje
testfile1
testfile4
// 복사 해주기(Permission denied? : 허가 거부)
<서버>
[root@junga ~]# ls -ld /test/scp
drwxr-xr-x 2 root root 23 1월 18 13:18 /test/scp // itbank는 other 755 이므로 w 쓰기 권한 없음!
[root@junga ~]# chmod 757 /test/scp/
[root@junga ~]#
[root@junga ~]# ls -ld /test/scp
drwxr-xrwx 2 root root 23 1월 18 13:18 /test/scp
<클라이언트>
[junga@localhost tmp]$ scp /tmp/testfile1 itbank@192.168.46.90:/test/scp/testfile1
or
[[junga@localhost tmp]$ scp testfile1 itbank@192.168.46.90:/test/scp/testfile1
Hello sshd Service~!
itbank@192.168.46.90's password:
testfile1 100% 0 0.0KB/s 00:00
* Openssh ← Service 1_2>
openssh 접속방법
- ssh 명령어를 이용하여 지정한 서버에 접속
- telnet 사용형식과 비슷함
1) ssh Server-IP
→ 접속할 때 이용할 사용자 계정을 지정하지 않았으므로 현재 로그인 되어있는
사용자 계정과 동일한 이름으로 상대방쪽으로 접속을 요청하게 됨
2) ssh -l 계정명 Server-IP // 이때 계정은 서버쪽 계정임
→ -l 옵션은 로그인 시 클라이언트쪽에서 지정한 계정으로 접속 요청을 하게 됨
3) ssh 계정명@Server-IP
→ 2)와 동일함
사용형식이 E-mail 주소와 비슷함
[서버]
[root@junga ~]# ifconfig | head -2
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.46.90 netmask 255.255.255.0 broadcast 192.168.46.255
[클라이언트]
1> root 로그인
permitlootlogin=no 라고 해놨으므로 접속 안됨!
2> 사용자 로그인
// client 사용자 계정으로 로그인
[junga@localhost ~]$ ssh 192.168.46.90
The authenticity of host '192.168.46.90 (192.168.46.90)' can't be established.
ECDSA key fingerprint is SHA256:ILbcgow74PqidyaqB/UMLU0RnVZmEJZMp2oy+N6dnmU.
ECDSA key fingerprint is MD5:0f:9b:2a:23:62:ca:f5:0c:14:3b:c0:cf:5c:6d:b5:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.46.90' (ECDSA) to the list of known hosts.
Hello sshd Service~!
junga@192.168.46.90's password:
Permission denied, please try again.
junga@192.168.46.90's password:
Permission denied, please try again.
junga@192.168.46.90's password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[junga@localhost ~]$
// server쪽 사용자 계정으로 로그인
[junga@localhost ~]$ ssh -l itbank 192.168.46.90
Hello sshd Service~!
itbank@192.168.46.90's password:
Last login: Wed Jan 17 13:39:00 2018 from ::ffff:192.168.46.57
[itbank@junga ~]$
[itbank@junga ~]$
// server쪽 사용자 계정으로 로그인 2
[itbank@junga ~]$ logout
Connection to 192.168.46.90 closed.
or
[itbank@junga ~]$ exit
logout
[junga@localhost ~]$
[junga@localhost ~]$ ssh itbank@192.168.46.90
Hello sshd Service~!
itbank@192.168.46.90's password:
Last login: Thu Jan 18 13:03:38 2018 from 192.168.46.85
[itbank@junga ~]$
[itbank@junga ~]$ pwd
/home/itbank
[itbank@junga ~]$
======================== [ Review] =======================
* Openssh(원격 서비스 2) ← Service 1_2>
openssh
- 원격 관리 서비스 중에 하나이며 데이터 전송시 암호화 통신을 하는 특성
- telnet, rsh, rlogin 서비스들은 데이터 전송시 암호화 통신을 하지 않으므로
제 3자가 sniffing(도둑질) 공격에 쉽게 노출이 됨
그래서 이러한 문제점을 해결하고자 SSH Service가 개발되었음
SSH(Secure SHell)
- 패킷이 암호화 되어 전송되기 때문에 제 3자가 패킷을 가로챘다 하더라도
해독할 키가 없으므로 내용을 파악하기가 어렵게 됨
암호화 알고리즘(Encrpytion Algorithm_
- 암호화에는 크게 대칭형과 비대칭형
1) 대칭형
- 비밀키 암호화 방식이라고도 불리움
- 암호화(평문→암호화)와 복호화(암호화→평문) 에 사용되는 키가 동일함
- 암호화와 복호화의 속도가 빠름
- 송신자와 수신자의 키 교환시 보안이 취약함
2) 비대칭형
- 공개키 암호화 방식이라고도 불리움
- 공개키와 개인키라는 하나의 쌍으로 이루어진 키를 사용함
- 일반적인 암호화 통신은 공개키로 함
- 비밀키 전달등의 키 교환이 필요가 없음
- 암호화와 복호화의 속도가 느림
- 대표적으로 RSA가 있음
openssh 패키지 유무를 확인!
/etc/ssh/sshd_config # 외워!!!
- ssh의 환경설정파일
17줄 : ssh 포트는 22번으로 규약
보안상 임의의 포트로 변경할 수도 있음
(참고로 포트관련 설정파일은 /etc/services)
cf) telnet : 23
ssh service는 sshd.service 임
19줄 : ssh service에 listen할 로컬 호스트 주소를 설정하는 항목
ex)
# ListenAddress 0.0.0.0
→ 모든 IP Address를 ssh service에서 듣겠다
LisstenAddress 192.168.x.x
→ 지정한 IP Address를 ssh service가 듣겠다
37줄 : 지정한 시간내에 로그인 하지 않으면 자동으로 접속을 끊을 시간을 설정(기본값으로 2분)
38줄 : 관리자로그인 허용 여부(기본값으로 허용)
보안상 관리자로그인 하용을 거부해야함
38 PermitRootLogin no # PermitRootLogin yes를 다음과 같이 변경 해줘야! (puTTY root 접속 access denied)
이걸 다시 원래대로 돌리면 puTTY root 접속 가능해짐!
ssh service restart 꼭!!!
39줄 : 로그인을 허용하기 앞서 파일 모드 및 사용자 홈 디렉터리 소유권과 원격 호스트의 파일들을
ssh service가 체크 할 수 있도록 허용
40줄 : 로그인할 때 비밀번호 오류 시 최대인증시도(기본값으로 6번)
41줄 : 최대 세션 연결 개수(기본값으로 10개)
65줄 : 비밀번호 인증 허용
69줄 : no ? // pam 인증과 겹쳐서 no 처리되있음
96줄 : PAM 인증
105줄 : ssh 로그인 시 /etc/motd 파일의 내용을 보여줄 것인지 허용 여부 // 메시지 출력 관련
106줄 : 로그인 시 지난번 로그인한 기록을 보여줄 것인지 허용 여부
116줄 : ssh service의 Process ID를 저장할 파일을 지정
123줄 : ssh service에 로그인 할 시 메시지 출력(광고)
123 #Banner none
123 Banner /test/ssh/banner
[root@junga ~]# systemctl restart sshd.service
[root@junga ~]#
[root@junga ~]# mkdir -p /test/ssh
[root@junga ~]#
[root@junga ~]# touch /test/ssh/banner // 쓰고자 하는 문구 쓰기
[root@junga ~]#
[root@junga ~]# vi /test/ssh/banner
[root@junga ~]#
netstat(network+statistics)
- 어떤 호스트(또는 서버)와 어떤 서비스로 연결되었는지 그리고 연결 상태는 어떤지에 대한
정보를 알 수 있음
사용형식
netstat [option]
option
-a : all(모든 소켓 정보)
-t : tcp(Transmission Control Protocol) 소켓연결정보
-u : udp(User Datagram Protocol) 소켓연결정보
-n : 10진수 수치
ex) * // 모든 ip => 0.0.0.0
-p : Program name
// 항목 Proto → 프로토콜 Recv-Q → 수신소켓 버퍼에 존재하는 바이트 수 Send-Q → 송신소켓 버퍼에 존재하는 바이트 수 Local Address → 로컬쪽 주소 Foreign Address → 상대방쪽 주소 State → 상태 상태의 종류 LISTEN : 연결 가능하도록 관련 서비스(daemon)이 떠 있고 연결 가능함을 알려줌 SYN-SENT : 연결을 요청한 상태 SYN-RECEIVED : 연결 요구에 대한 응답을 준 후 확인 메시지를 기다리고 있는 상태 ESTABLISHED : 위의 3단계 과정이 종료된 후 연결이 완료된 상태 FIN-WAIT, FIN2-WAIT, CLOSE-WAIT: 연결 종료를 위해 요청을 받은 후의 과정 CLOSING : 전송된 메시지가 유실된 상태 TIME-WAIT : 연결 종료 후 한동안 유지되고 있는 상태 CLOSED : 연결이 완전히 종료된 상태 PID : 프로세스 아이디 Program name : 프로그램명
[root@junga ~]# rpm -qa | grep openssh*
openssh-clients-7.4p1-12.el7_4.x86_64
openssl-libs-1.0.2k-8.el7.x86_64
openssh-server-7.4p1-12.el7_4.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
openssl-1.0.2k-8.el7.x86_64
openssh-7.4p1-12.el7_4.x86_64
[root@junga ~]#
[root@junga ~]# ls -l /etc/ssh/sshd_config // openssh 설정 파일
-rw------- 1 root root 3907 9월 7 07:17 /etc/ssh/sshd_config
#[root@junga ~]#
[root@junga ~]# cp /etc/ssh/sshd_config /backup/ // 작업 전에 미리 백업
[root@junga ~]#
[root@junga ~]# ls -l /backup/
합계 28
-rwxr-xr-x 1 root root 8702 1월 12 13:06 00_header
-rw-r--r-- 1 root root 5078 1월 12 13:06 grub.cfg
-rw------- 1 root root 3907 1월 17 14:02 sshd_config
-r--r----- 1 root root 3938 1월 17 13:10 sudoers
[root@junga ~]#vi /etc/ssh/sshd_config
17 #Port 22 // ssh port
# vi /etc/services // port list 파일
15 # The Well Known Ports are those from 0 through 1023. // 기 존재하는 것들이므로 쓰지 말것!
16 # The Registered Ports are those from 1024 through 49151
17 # The Dynamic and/or Private Ports are those from 49152 through 65535
46 ssh 22/tcp # The Secure Shell (SSH) // ssh 가 tcp 프로토콜 쓰는것 확인!
// ssh port 변경해보기
17 Port 50000 // ssh port 50000으로 변경, 주석# 지울것!
:wq
// sshd 재 시작
[root@junga ~]#
[root@junga ~]# systemctl restart sshd.service
[root@junga ~]#
// 방화벽 확인?
방화벽 설정 pg 에서
① 해당 서비스 체크 유무 확인 (ssh)
② 포트: 50000, 프로토콜: tcp로 추가
> puTTY port 50000 으로 바꾸고 접속해보기!
// 방화벽 이전 상태로 돌리기
①방화벽 프로그램에서 port 추가한거 삭제
② vi 편집
[root@junga ~]# vi /etc/ssh/sshd_config
17 #Port 22
[root@junga ~]# systemctl restart sshd.service // 방화벽 재시작
// 서비스 상태 이상 시 확인(자세히)
[root@junga ~]# systemctl -l status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since 수 2018-01-17 14:22:41 KST; 49s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 4930 (sshd)
CGroup: /system.slice/sshd.service
└─4930 /usr/sbin/sshd -D
1월 17 14:22:41 junga.kgitbank systemd[1]: Starting OpenSSH server daemon...
1월 17 14:22:41 junga.kgitbank sshd[4930]: Server listening on 0.0.0.0 port 50000.
1월 17 14:22:41 junga.kgitbank sshd[4930]: Server listening on :: port 50000.
1월 17 14:22:41 junga.kgitbank systemd[1]: Started OpenSSH server daemon.
=> Failed 가 뜬 경우 어디가 이상한지 확인하고 해당 부분 확인!
// 실행 중인 서비스 정보
[root@junga ~]# netstat -atunp // 항목 Proto → 프로토콜 Recv-Q → 수신소켓 버퍼에 존재하는 바이트 수 Send-Q → 송신소켓 버퍼에 존재하는 바이트 수 Local Address → 로컬쪽 주소 Foreign Address → 상대방쪽 주소 State → 상태 상태의 종류 LISTEN : 연결 가능하도록 관련 서비스(daemon)이 떠 있고 연결 가능함을 알려줌 SYN-SENT : 연결을 요청한 상태 SYN-RECEIVED : 연결 요구에 대한 응답을 준 후 확인 메시지를 기다리고 있는 상태 ESTABLISHED : 위의 3단계 과정이 종료된 후 연결이 완료된 상태 FIN-WAIT, FIN2-WAIT, CLOSE-WAIT: 연결 종료를 위해 요청을 받은 후의 과정 CLOSING : 전송된 메시지가 유실된 상태 TIME-WAIT : 연결 종료 후 한동안 유지되고 있는 상태 CLOSED : 연결이 완전히 종료된 상태 PID : 프로세스 아이디 Program name : 프로그램명
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1144/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5054/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 957/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1089/master
tcp 0 0 192.168.46.90:50000 192.168.46.57:50538 ESTABLISHED 4738/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 5054/sshd
tcp6 0 0 :::23 :::* LISTEN 1/systemd
tcp6 0 0 ::1:631 :::* LISTEN 957/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1089/master
tcp6 0 0 192.168.46.90:23 192.168.46.57:50375 ESTABLISHED 1/systemd
udp 0 0 192.168.122.1:53 0.0.0.0:* 1144/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1144/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 762/dhclient
udp 0 0 0.0.0.0:3281 0.0.0.0:* 762/dhclient
udp 0 0 0.0.0.0:5353 0.0.0.0:* 575/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 546/chronyd
udp 0 0 0.0.0.0:38262 0.0.0.0:* 575/avahi-daemon: r
udp6 0 0 :::39096 :::* 762/dhclient
udp6 0 0 ::1:323 :::* 546/chronyd