auto login

Submitted by khju on 2018.09.27.(Thu) - 18:04

초기에 부팅 시 터미널에 로그인이 가능하도록 되어져 있습니다.

root/root 또는 debian/temppwd 를 입력하여 로그인을 하고 있는데 이부분에서 로그인을 하지 않고 바로 root권한으로 자동 로그인이 되는지 궁금합니다.

westporch

작성: 2018.10.01.(Mon) - 03:13

수정: 2018.10.08.(Mon) - 01:07

지식에 기반한 인증(아이디, 비밀번호)이 아니더라도 공개키 암호 시스템에서 사용하는 키쌍(공개키, 개인키)을 통해 인증을 할 수도 있습니다.
(참고로 공개키는 외부에 공개되어도 되지만, 개인키는 반드시 자신만 알고 있어야 합니다. 개인키가 절대로 외부에 알려져서는 안됩니다)
예를 들어 전자 서명은 공개키 암호 시스템(RSA)의 원리를 이용하여 서명자 인증 및 부인 방지 등의 기능을 제공합니다.

ssh에서도 공개키 암호 시스템을 사용하기 때문에, RSA-2048(ssh-keygen 명령으로 키쌍 생성시 기본값으로 설정됨) 암호 시스템을 사용하여 생성한 키쌍을 통해 인증을 할 수 있습니다.
따라서 아이디와 비밀번호를 입력하지 않더라도, 자동으로(키 인증 만으로) 루트 계정으로 접속할 수 있습니다.
물론 ssh의 설정 파일(/etc/ssh/sshd_config)에서 root로 접속하는 것을 허용해야 하며 포트를 개방해야 합니다.

하지만, 편리한 만큼 위험도 따릅니다.
공개키 암호 시스템에서 사용하는 RSA 알고리즘이 소인수분해의 어려움을 이용했기 때문에 개인키를 절대로 알아낼 수 없다고 할지라도, 루트 계정으로 곧장 접속을 허용하는 것은 위험합니다.

아마 내부망에 있는 테스트 서버나 개발 서버 등을 편하게 사용하고자, 루트 계정으로 자동 접속을 하시려는게 아닐까 싶네요.

다음은 ssh 키 인증을 설정하는 방법입니다.


1. 서버 정보
1.1 클라이언트

  • 호스트네임: test-vm-01
  • IP: 192.168.1.99
  • 계정: westporch
     

1.2. 서버

  • 호스트네임: test-vm-02
  • IP: 192.168.1.100
  • 계정: root

     

2. 시나리오
클라이언트(test-vm-01)의 사용자 westporch가 ssh 키 인증을 설정한 후, 서버(test-vm-02)의 루트 계정으로 자동 접속합니다.


3. ssh 키 인증 설정 과정 및 자동 접속 테스트
3.1. 클라이언트에서 키 쌍(공개키, 개인키)을 생성

ssh-keygen 명령으로 키 쌍(공개키, 개인키)을 생성합니다.

-----------------------------------------
westporch@test-vm-01:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/westporch/.ssh/id_rsa): 
Created directory '/home/westporch/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/westporch/.ssh/id_rsa.
Your public key has been saved in /home/westporch/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:BTZ7AKgDL8SrUlhbw0G2jzTGbKmd136Qr+zg7LwaS0w westporch@test-vm-01
The key's randomart image is:
+---[RSA 2048]----+
|.  o+o..=        |
|.o.+=o . =       |
|.=.+X.  . o      |
|o.** = . +       |
|.o..E o S        |
|o  o . . o       |
|.   + . . o      |
|   . * o o       |
|    oo*o+        |
+----[SHA256]-----+
-----------------------------------------


생성된 공개키(~/.ssh/id_rsa.pub)는 외부에 공개되어도 되지만,
개인키(~/.ssh/id_rsa)는 절대로 외부에 공개하면 안됩니다.

-----------------------------------------
westporch@test-vm-01:~/.ssh$ ls -lh
합계 12K
-rw------- 1 westporch westporch 1.7K 10월  1 00:40 id_rsa
-rw-r--r-- 1 westporch westporch  402 10월  1 00:40 id_rsa.pub
-rw-r--r-- 1 westporch westporch  222 10월  1 00:42 known_hosts
-----------------------------------------


3.2. 클라이언트의 공개키를 서버(도착지)에 복사

-----------------------------------------
westporch@test-vm-01:~$ ssh-copy-id root@192.168.1.100
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/westporch/.ssh/id_rsa.pub"
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
ECDSA key fingerprint is SHA256:vsyoOlv44YavJKRnv/1vR+Nyt36vuyKQXUrLIsw2Kao.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.100's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.1.100'"
and check to make sure that only the key(s) you wanted were added.
-----------------------------------------


3.3. 자동 접속 테스트
아이디와 비밀번호를 입력하지 않고, 자동으로 test-vm-02의 루트 계정으로 접속하였습니다.

-----------------------------------------
westporch@test-vm-01:~$ ssh root@192.168.1.100
Linux test-vm-02 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3+deb9u2 (2018-08-13) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Oct  1 00:36:26 2018 from 192.168.1.90
root@test-vm-02:~#
root@test-vm-02:~# id
uid=0(root) gid=0(root) groups=0(root)
-----------------------------------------

 

* 내용 수정(2018.10.08.)
ip주소를 잘못 적어서 수정했습니다.
192.168.0.99 → 192.168.1.99
192.168.0.100 →  192.168.1.100