본문 바로가기
Development Tips

Ubuntu Server 16.04 LTS - SSH 인스톨 및 설정방법

by Deafhong 2017. 9. 29.
반응형
안녕하세요. 데프홍입니다.
이번에는 Ubuntu Server 16.04 LTS 버전에서 SSH 에 대한 인스톨 및 설정방법에 대해서 포스팅을 하겠습니다.

아주 간단하게 기본적인 것만 알아도 되겠지만, 향후에 고급설정이 필요할 때가 있을 수도 있습니다.
그에 따라서 기본옵션과 고급옵션 두가지로 나눠서 설명하겠습니다.

아래 내용은 해당 주소를 참조하여 작성한 글임을 밝힙니다.

참고로, root 계정이 아닌 사용자 계정(jwhong) 으로 접속해서 실행한 결과를 반영한 것임을 참고해주세요.


SSH Server 설치

  1. Update repositories.
    말 그대로, Ubuntu Server 에 설치된 프로그램들을 업데이트 해주는 명령어입니다.
sudo apt-get update
sudo apt-get upgrade

  1. Install SSH Server
    Ubuntu Server 에서 다른 클라이언트로 접속을 해서 사용하는 것이 아닌, 외부에서 접속을 받아서 처리를 해주는 것이기 때문에, SSH Server 을 설치해줍니다. 반대로, 외부로 SSH 를 쓸 일이 있다면, SSH Client 를 설치해주면 되겠지요?
sudo apt-get install openssh-server

Base Configuration ( 기본 설정 )

  1. After installation I will show how to configure ssh server. Open ssh config file with the following command:
    인스톨 한 후에, ssh server 설정을 어떻게 하는지 보여줄 것이다. 아래 명령어를 쳐서 ssh 설정 파일을 열어본다.
sudo nano /etc/ssh/sshd_config
          열고 나면 다음 아래와 같은 내용들이 나올 것이다.



  1. If you want to change ssh port you have to find ‘Port’ line and change the number of the port. For example I will change to 22222.
    만약 ssh 포트번호를 변경하고 싶다면, ‘Port’ 라인을 찾아서 그 옆의 숫자를 바꾸면 된다. 아래는 22222 로 바꾼 예시이다.
Port 22222

  1. I will set max login attempts to be 3. After 3 wrong login attempts you will disconect. This is very important for security of your server and this can be used for prevention from brute force attack (see my Theme 4). Add this line bellow Port:
    최대 로그인 시도 횟수를 3으로 설정할 것이다. 로그인이 3번 잘못되었을 경우, 차단될 것이다. 이것은 서버 보안에 매우 중요하며 무차별 대입 공격을 막기 위해 사용할 수 있다 (내 테마 4 참조). 이 줄을 Port 아래에 추가하십시오 :
MaxAuthTries 3

  1.  Allow certain users to login on your server and deny all other users. I will add ‘zimbra’ users because my Zimbra Mail Serve should have access. For more information about Zimbra Mail Server configuration read theme 12. Add the following line at the end of the file and after that save the file /etc/ssh/sshd_config.
    특정 사용자가 서버에 로그인을 하는 걸 허용하고, 다른 모든 사용자를 거부하세요. 내 Zimbra Mail Serve가 액세스 할 수 있어야하므로 ‘zimbra' 사용자를 추가 할 것입니다. Zimbra 메일 서버 구성에 대한 더 자세한 정보는 테마 12를 읽으십시오. 파일 끝에 다음 행을 추가 한 후 / etc / ssh / sshd_config 파일을 저장하십시오.
AllowUsers mslavov zimbra

  1. Restart ssh service with the following command:
    아래 커맨트를 통해서 SSH 서비스를 재시작하세요.
sudo service ssh restart

  1. Show ssh status with systemctl status ssh
    systemctl status ssh 를 통해서 ssh 상태를 보여줍니다. ( 활성화 되고 있다는 active (running) 표시를 확인하세요 )



이제 두명의 사용자만이 서버에 엑세스(접근) 할 수 있게 될 것입니다.

p.s> 여기까지만 해도 기본적으로 사용하시는 데에는 크게 무리가 없을 것 같습니다. 연습용이나, 개인용으로만 사용을 하실거면 여기까지 하셔도 됩니다.
그 이상으로 규모를 크게 키우실 계획이라면, 아래 고급설정을 통해서 보다 더 안전하게 서버를 보호하시는 것을 권장드립니다.


Advanced Configuration ( 고급설정 )

I will show you How To Configure SSH Key-Based Authentication on a Linux Server.  In my opinion this is the best way to protect from unauthorised access to your server. Unfortunately this is not the most convenient one, because you have to bring the key with you. My advice is to use the configuration shown above.
나는 당신에게 리눅스 서버에서 SSH 키 기반 인증을 구성하는 방법을 보여줄 것이다. 내 생각에 이것은 서버에 대한 무단 접근으로부터 보호하는 가장 좋은 방법이다. 불행히도 이것은 당신이 열쇠를 가져와야하기 때문에 가장 편리한 열쇠는 아닙니다. 나의 조언은 위의 구성을 사용하는 것이다.

  1.  Create folder, change permission and navigate to new folder with the following commands:
    커맨트를 실행하여 폴더를 만들고, 권한을 변경 후, 새로운 폴더로 이동하세요.
mkdir .ssh/; chmod 700 .ssh/; cd .ssh/;

  1. Create folder, change permission and navigate to new folder with the following commands:
    커멘트를 실행하여 파일을 만들고 권한을 변경해 주세요. ( 위에 영문은 잘못 적은 것 같음.. )
touch authorized_keys; chmod 600 authorized_keys

  1. Show new files.
    새로 만든 파일을 보여준다.
ls -ltra

  1. Generate Keys - If you ‘Enter passphrase’ you must remember it and use it in the following steps:
    키 생성 - ‘암호 입력’ 을 사용하는 경우, 이를 기억하고, 다음 단계에서 사용하세요.



  1. Append the public key to authorized_keys and remove the uploaded copy.
    authorized_keys 에 공개키를 추가하고, 업로드 된 사본을 제거하세요.
cat id_rsa.pub >> authorized_keys

  1. Edit the ssh server config file with ‘nano /etc/ssh/sshd_config’ to make sure that public key authentication is enabled (it should be enabled by default) :
    'nano / etc / ssh / sshd_config'를 사용하여 ssh 서버 설정 파일을 편집하여 공개 키 인증이 활성화되어 있는지 확인하십시오 (기본적으로 활성화되어 있어야합니다) :
nano /etc/ssh/sshd_config

  1. These entries must be set to YES
    이 항목은 YES로 설정되어야합니다.
RSAAuthentication yes
PubkeyAuthentication yes

  1. The following settings should be set to NO:
    다음 설정을 NO로 설정해야합니다.
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

  1. Restart ssh service with the following command:
    다음 명령을 사용하여 ssh 서비스를 다시 시작하십시오.
sudo service ssh restart

  1. Now you must get private key code.  (user name) 는 사용자 계정이름
    이제 개인 키 코드를 얻어야합니다. ( 이 부분은 Windows 에서 putty 로 접속을 해서 카피를 하시는게 편할듯 합니다. )
nano /(user name)/.ssh/id_rsa

  1.  Paste in notepad and save without extension
    메모장에 복사한 개인 키 코드를 붙여넣고 확장자없이 저장하세요. ( 파일명은 ‘id_rsa.ppk’ 으로 저장 )

  1. When you connect to your server you must browse your ‘id_rsa.ppk’ file in putty.
    putty 에서 서버로 연결을 할 때, ‘id_rsa.ppk’ 파일을 찾아야 합니다.
    putty 에서 Connection - SSH - Auth 란에서 private key file 를 지정하는 부분이 있는데 Browse 을 통해서 설정해주시면 됩니다.



이걸로 SSH 인스톨 및 설정방법에 대해서 포스팅을 마치도록 하겠습니다.



반응형