• 네트워크 설정과 관리

    2021. 6. 5.

    by. 공상개발

     

    # 네트워크 정보 보기

    ifconfig 명령으로 현재 네트워크 상태를 볼 수 있다.
    우분투 18 버전 이후에는 이 툴이 기본적으로는 설치되어 있지 않으므로 설치한 후, ifconfig 명령 입력

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    hjw@Desktop:~/work/ch8$ sudo apt install net-tools
    [sudo] password for hjw: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    net-tools is already the newest version (1.60+git20180626.aebd88e-1ubuntu1).
    The following packages were automatically installed and are no longer required:
      linux-headers-5.8.0-50-generic linux-hwe-5.8-headers-5.8.0-50
      linux-image-5.8.0-50-generic linux-modules-5.8.0-50-generic
      linux-modules-extra-5.8.0-50-generic
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
     
    cs

     

     

    # OpenSSH

    Secure Shell protocol
       SSH 프로토콜은 인터넷 상의 두 호스트 사이에 통신 암호화, 인증 기술들을 사용하여 안전한 접속과 통신을 제공하는 프로토콜이다.
       인증 방법으로는 주로 public key를 사용한 전자 서명을 사용하지만, 이러한 인증이 안 될 때에는 기존과 같은 plain text 암호 방식을 사용하기도 한다.
       기존에 있던 보안이 취약한 프로토콜들인 rlogin, rsh, rcp, telnet 등을 대체하여 임의의 포트에 대해 안전한 통신 채널을 제공한다.
     
    OpenSSH
       Secure Shell protocol family의 오픈소스 소프트웨어이다.
       server : sshd
       client : ssh, scp

     

    클라이언트 프로그램 설치(클라이언트 컴퓨터에 설치)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    hjw@Desktop:~/work/ch8$ sudo apt install openssh-client
    [sudo] password for hjw: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    openssh-client is already the newest version (1:8.2p1-4ubuntu0.2).
    The following packages were automatically installed and are no longer required:
      linux-headers-5.8.0-50-generic linux-hwe-5.8-headers-5.8.0-50
      linux-image-5.8.0-50-generic linux-modules-5.8.0-50-generic
      linux-modules-extra-5.8.0-50-generic
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
     
    cs

     

    저는 미리 다운로드하여서 위와 같이 나타납니다.

    서버에도 서버 프로그램을 설치해 주세요. 명령 : sudo apt install openssh-server 

     

     

    ssh를 이용한 원격 접속(Client 컴퓨터에서)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    hjw@Desktop:~/work/ch8$ ssh hjw@192.168.194.131
    Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-73-generic x86_64)
     
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
     
      System information as of Sat 05 Jun 2021 08:12:21 AM UTC
     
      System load:  0.0                Processes:              221
      Usage of /:   35.5% of 18.57GB   Users logged in:        1
      Memory usage: 8%                 IPv4 address for ens33: 192.168.194.131
      Swap usage:   0%
     
     * Super-optimized for small spaces - read how we shrank the memory
       footprint of MicroK8s to make it the smallest full K8s around.
     
       https://ubuntu.com/blog/microk8s-memory-optimisation
    .
    .
    .
    cs

     

    한번 로그인하면 ~/. ssh/known_hosts 파일에 서버의 정보가 등록된다.

    서버에서 로그아웃 : ^D 혹은 logout

    1
    2
    3
    4
    5
    6
    7
    hjw@hongserver:~$ hostname
    hongserver
    hjw@hongserver:~$ logout
    Connection to 192.168.194.131 closed.
    hjw@Desktop:~/work/ch8$ hostname
    Desktop
     
    cs

     

     

    # scp를 이용한 파일 전송

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    hjw@Desktop:~/work/ch8$ scp f1 hjw@192.168.194.131:~/f2
    f1                                            100%   12    18.7KB/s   00:00    
    hjw@Desktop:~/work/ch8$ ssh hjw@192.168.194.131
    Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-73-generic x86_64)
    .
    .
    .
    hjw@hongserver:~$ ls -l
    total 4
    -rw-rw-r-- 1 hjw hjw 12 Jun  5 08:18 f2
    hjw@hongserver:~$ cat f2
    sfsdf
    dsfdf
    hjw@hongserver:~$ logout
    Connection to 192.168.194.131 closed.
    cs

     

     

    # 패스워드 없이 ssh 사용하기

    Passwordless ssh
       미리 설정해 두면 패스워드 없이 ssh와 scp를 사용할 수 있다.
       두 개의 키(a private key and a public key)를 사용한 인증을 한다.
       두 개의 키를 생성해서 public key를 원격 서버의 ~/. ssh/authorized_keys 파일에 복사해서 저장해 두면 패스워드 없이 ssh와 scp 사용할 수 있다.
     
    키 생성(client 컴퓨터에서 실행)
       ssh-keygen 명령을 사용해서 두 개의 키를 생성한다.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    hjw@Desktop:~/work/ch8$ ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/hjw/.ssh/id_rsa): 
    /home/hjw/.ssh/id_rsa already exists.
    Overwrite (y/n)? y
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/hjw/.ssh/id_rsa
    Your public key has been saved in /home/hjw/.ssh/id_rsa.pub
    The key fingerprint is:
    SHA256:qzS/uud0g6gEZgGB7WG8G77jVoBdsuFHtr3q9LB1QxM hjw@Desktop
    The key's randomart image is:
    +---[RSA 3072]----+
    |++               |
    |..B +            |
    | *.X o  E        |
    |. O.o .  .       |
    | .+=   .S        |
    | oo.. .o +       |
    |   o+.= * o      |
    |  +o.B *.o .     |
    | o.o+ ==+.       |
    +----[SHA256]-----+
     
    cs

     

     

     

    public key : ~/. ssh/id_rsa.pub 파일에 저장되어 있다.
    private key : ~/. ssh/id_rsa 파일에 저장되어 있다.
    1
    2
    3
    4
    5
    6
    7
    8
    hjw@Desktop:~$ pwd
    /home/hjw
    hjw@Desktop:~$ ls -l .ssh
    total 12
    -rw------- 1 hjw hjw 2602 Jun  5 01:24 id_rsa
    -rw-r--r-- 1 hjw hjw  565 Jun  5 01:24 id_rsa.pub
    -rw-r--r-- 1 hjw hjw  222 Jun  1 01:35 known_hosts
     
    cs

     

     

    키 복사 및 저장

    • ssh-copy-id 명령을 사용해서 id_rsa.pub 파일의 내용을 원격 서버의 ~/. ssh/authorized_keys 파일의 끝에 붙여 넣는다.
    • ssh-copy-id는 client 컴퓨터에서 실행해야 한다.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    hjw@Desktop:~$ ssh-copy-id hjw@192.168.194.131
    /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
     
    Number of key(s) added: 1
     
    Now try logging into the machine, with:   "ssh 'hjw@192.168.194.131'"
    and check to make sure that only the key(s) you wanted were added.
     
    cs

     

     

    위의 과정을 올바르게 진행했으면 패스워드 없이 로그인이 됩니다.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    hjw@Desktop:~$ ssh hjw@192.168.194.131
    Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-73-generic x86_64)
     
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
     
      System information as of Sat 05 Jun 2021 08:31:26 AM UTC
     
      System load:  0.0                Processes:              229
      Usage of /:   35.5% of 18.57GB   Users logged in:        1
      Memory usage: 9%                 IPv4 address for ens33: 192.168.194.131
      Swap usage:   0%
     
     * Super-optimized for small spaces - read how we shrank the memory
       footprint of MicroK8s to make it the smallest full K8s around.
     
       https://ubuntu.com/blog/microk8s-memory-optimisation
     
    75 updates can be installed immediately.
    0 of these updates are security updates.
    To see these additional updates run: apt list --upgradable
     
     
    Last login: Sat Jun  5 08:19:29 2021 from 192.168.194.128
     
    cs

     

     

    # 패스워드 없이 명령 실행하기

    • ssh를 이용해서 서버 컴퓨터에서 명령을 실행하고 결과를 클라이언트 모니터에서 보는 것도 가능합니다.

    ssh login_name@server_address "command"

    1
    2
    3
    4
    5
    6
    hjw@Desktop:~$ hostname
    Desktop
    hjw@Desktop:~$ ssh hjw@192.168.194.131 "ls -l"
    total 4
    -rw-rw-r-- 1 hjw hjw 12 Jun  5 08:18 f2
     
    cs

     

     

    'Computer Science > Linux' 카테고리의 다른 글

    파일 시스템 관리  (0) 2021.06.06
    예약 작업 처리  (0) 2021.06.06
    시스템 관리 (3)  (0) 2021.06.05
    시스템 관리 (2)  (0) 2021.06.01
    시스템 프로그래밍 C.2  (0) 2021.05.28

    댓글