OS/Linux

Ubuntu - SSH Server 설치 및 접속하기

TechNote.kr 2019. 11. 11. 00:04
728x90

 Ubuntu machine 와의 연결에 ssh 를 사용하기 위해서는 해당 Ubuntu machine에는 SSH Server가 설치되어 있어야 하고, 해당 Server에 접속하려는 PC 에서는 SSH Client 설치가 필요하다. 

 

 

SSH Server의 설치


Ubuntu 에서는 아래와 같이 openssh-server를 설치한다. 

(Ubuntu 14/16/18 등 버전에 따라 큰 차이가 없음)

 

$ sudo apt install openssh-server

user@TechNote:~$ sudo apt install openssh-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ncurses-term openssh-sftp-server ssh-import-id
Suggested packages:
  molly-guard monkeysphere rssh ssh-askpass
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 199 not upgraded.
Need to get 637 kB of archives.
After this operation, 5,316 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://kr.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04 [248 kB]
Get:2 http://kr.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssh-sftp-server amd64 1:7.6p1-4ubuntu0.3 [45.6 kB]
Get:3 http://kr.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssh-server amd64 1:7.6p1-4ubuntu0.3 [333 kB]
Get:4 http://kr.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ssh-import-id all 5.7-0ubuntu1.1 [10.9 kB]
Fetched 637 kB in 9s (71.3 kB/s)                                              
Preconfiguring packages ...
Selecting previously unselected package ncurses-term.
(Reading database ... 126276 files and directories currently installed.)
Preparing to unpack .../ncurses-term_6.1-1ubuntu1.18.04_all.deb ...
Unpacking ncurses-term (6.1-1ubuntu1.18.04) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a7.6p1-4ubuntu0.3_amd64.deb ...
Unpacking openssh-sftp-server (1:7.6p1-4ubuntu0.3) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a7.6p1-4ubuntu0.3_amd64.deb ...
Unpacking openssh-server (1:7.6p1-4ubuntu0.3) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.7-0ubuntu1.1_all.deb ...
Unpacking ssh-import-id (5.7-0ubuntu1.1) ...
Setting up ncurses-term (6.1-1ubuntu1.18.04) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Setting up openssh-sftp-server (1:7.6p1-4ubuntu0.3) ...
Processing triggers for systemd (237-3ubuntu10.24) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up ssh-import-id (5.7-0ubuntu1.1) ...
Setting up openssh-server (1:7.6p1-4ubuntu0.3) ...

Creating config file /etc/ssh/sshd_config with new version
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:LLPMNmm1D4SL5HORHoSVdVUnchUaEGZH1Mt9urYDRjE root@TechNote (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:TKhnSTlkWfnbPJpO1GATo01CkzTuGKtcHbq70MkbuzE root@TechNote (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:vw7ejISV4KAyM9m4DJ5BJMPFeqhjO8o7DoOH1i8wCnA root@TechNote (ED25519)
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for systemd (237-3ubuntu10.24) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
user@TechNote:~$ 

 

설치 후에는 바로 ssh server가 구동하는데 아래와 같이 22 port 가 LISTEN 상태인지를 확인하면 된다.

user@TechNote:~$ netstat -an|grep :22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN 
user@TechNote:~$

 

 

SSH Client를 이용한 접속


 SSH Server에는 Linux 에서도 접속이 가능하고, Windows 에서도 접속이 가능하지만 Windows 를 예로 들어 설명하면 다음과 같다. 일반적으로 Windows 에서 가장 많이 사용되는 SSH Client program 중 하나인 putty 를 사용하였다. 

 

1) putty 를 실행하면 아래와 같이 PuTTY Configuration 화면이 나오고, Host Name 에 접속하고자 하는 SSH Server의 주소를 기입하고 Connection type 을 SSH 로 한 후 Open 버튼을 눌러준다.

 

 

2) 처음 접속하는 SSH Server 의 경우 아래와 같이 PuTTY Security Alert 가 발생하는데 "예(Y)" 버튼을 선택한다. 

 

 

3) 이후 아래와 같이 접속이 되고 해당 서버의 terminal 사용이 가능해진다. 

 

 

 

 

 

 

728x90