서버 원격 접속 오류 지원(Linux)
    • PDF

    서버 원격 접속 오류 지원(Linux)

    • PDF

    Article Summary

    Linux 서버에 오류가 발생하여 원격 접속이 어려울 때 접속 문제를 해결하는 방법을 설명합니다.

    참고

    서버 접속에 문제가 발생하면 네이버 클라우드 플랫폼 콘솔의 서버 목록에서 [서버 접속 콘솔] 버튼이 활성화됩니다.
    server-ts-remote-win-vpc_example_ko

    ACG 설정 확인

    서버에 원격으로 접속할 수 없는 경우, 가장 먼저 접속하려는 리소스의 IP 또는 Subnet이 ACG에서 허용되었는지 확인해 주십시오.

    • ACG의 Inbound 규칙에서 다음 서비스에 대해 해당 포트가 올바르게 허용되어 있는지 확인해 주십시오(ACG 설정 참고).
      서비스허용 포트
      SSH
      RDP

    원격 접속 환경 확인

    서버의 ACG 설정에 이상이 없는 경우, 다음 절차에 따라 운영 체제별 접속 환경 설정을 확인해 주십시오.

    Linux 서버(CentOS 7 기준)

    다음 절차에 따라 CentOS 7 운영 체제를 사용하는 Linux 서버의 접속 환경을 확인해 주십시오.

    1. SSH 데몬 상태 확인

    SSH 데몬 상태를 확인하는 방법은 다음과 같습니다.

    1. 다음 명령어를 입력해 SSH 데몬이 정상적으로 실행 중인 상태인지 확인해 주십시오.
      # systemctl status sshd
      
      server-ts-remote-lin-vpc_deamon_check_centos
      • active (running)로 표시되는 경우 정상 실행 중입니다.
      • inactive로 표시되는 경우 SSH 데몬을 기동해 주십시오.
      • 데몬 기동 중 오류가 발생하는 경우 서버 로그를 확인해 SSH 데몬이 정상적으로 기동되도록 조치해 주십시오.
    2. 다음 명령어를 입력해 ssh 서비스가 22번 포트로 LISTEN하는지 확인해 주십시오.
      • 22번 포트는 Ncloud에서 제공하는 서버의 기본 설정값입니다. 다른 포트로 수정한 경우 해당 포트를 ACG에서 허용했는지 확인하고 해당 포트로 검색해 주십시오.
      # netstat -nap | grep ssh
      tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      788/sshd
      tcp        0     64 10.0.1.6:22             61.83.152.147:54479     ESTABLISHED 75194/sshd: root@pts
      tcp6       0      0 :::22                   :::*                    LISTEN      788/sshd
      
    3. 다음 명령어를 입력해 ssh 설정 파일(sshd_config)에서 PortListenAddress 항목에 설정된 부분이 있는지 확인해 주십시오.
      • 기본 설정은 주석 처리되어 있습니다.
      # vi /etc/ssh/sshd_config
      #       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $
      
      # This is the sshd server system-wide configuration file.  See
      # sshd_config(5) for more information.
      
      # This sshd was compiled with PATH=/usr/local/bin:/usr/bin
      
      # The strategy used for options in the default sshd_config shipped with
      # OpenSSH is to specify options with their default value where
      # possible, but leave them commented.  Uncommented options override the
      # default value.
      
      # If you want to change the port on a SELinux system, you have to tell
      # SELinux about this change.
      # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
      #
      #Port 22
      #AddressFamily any
      #ListenAddress 0.0.0.0
      #ListenAddress ::
      
      # The default requires explicit activation of protocol 1
      #Protocol 2
      

    2. hosts.deny 설정 상태 확인

    hosts.allow 파일과 hosts.deny 파일에 설정된 부분이 있는지 확인해 주십시오. hosts.allow 파일과 hosts.deny 파일은 특정 클라이언트에 대한 서비스 허용 및 차단을 제어합니다.

    • 기본 설정은 주석 처리되어 있습니다.
    # cat /etc/hosts.allow
    #
    # hosts.allow   This file contains access rules which are used to
    #               allow or deny connections to network services that
    #               either use the tcp_wrappers library or that have been
    #               started through a tcp_wrappers-enabled xinetd.
    #
    #               See 'man 5 hosts_options' and 'man 5 hosts_access'
    #               for information on rule syntax.
    #               See 'man tcpd' for information on tcp_wrappers
    #
    # cat /etc/hosts.deny
    #
    # hosts.deny    This file contains access rules which are used to
    #               deny connections to network services that either use
    #               the tcp_wrappers library or that have been
    #               started through a tcp_wrappers-enabled xinetd.
    #
    #               The rules in this file can also be set up in
    #               /etc/hosts.allow with a 'deny' option instead.
    #
    #               See 'man 5 hosts_options' and 'man 5 hosts_access'
    #               for information on rule syntax.
    #               See 'man tcpd' for information on tcp_wrappers
    
    참고
    • /etc/hosts.allow, /etc/hosts.deny 파일은 tcp_wrappers만 제어하며, 규칙이 적용되는 순서는 다음과 같습니다.
      1. /etc/hosts.allow 파일에 정의된 호스트의 접속은 허용
      2. /etc/hosts.allow 파일에 정의되지 않고 /etc/hosts.deny 파일에 정의된 호스트의 접근은 거부
      3. 둘 중 한 파일에도 정의되지 호스트의 접속은 허용
    • tcp_wrappersssh, telnet, ftpxinetd가 관리하는 데몬들의 특정 서비스만 제어할 수 있습니다.

    3. 방화벽 확인

    방화벽 상태를 확인하는 방법은 다음과 같습니다.

    • firewalld
      firewalld에서 ssh 거부 규칙을 정의했는지 확인하고, firewalld를 실행해야 하는 경우 ssh 거부 규칙을 제외해 주십시오(기본 설정: 규칙 없음).

      # firewall-cmd --list-all
      public
         target: default
         icmp-block-inversion: no
         interfaces:
         sources:
         services: dhcpv6-client ssh
         ports:
         protocols:
         masquerade: no
         forward-ports:
         sourceports:
         icmp-blocks:
         rich rules:
      
    • iptables
      iptables.service가 설치된 경우 iptables에서 ssh 거부 규칙을 정의했는지 확인하고, ssh 거부 규칙을 제외해 주십시오(기본 설정: 규칙 없음).

      # iptables -L
      Chain INPUT (policy ACCEPT)
      target     prot opt source               destination
      
      Chain FORWARD (policy ACCEPT)
      target     prot opt source               destination
      
      Chain OUTPUT (policy ACCEPT)
      target     prot opt source               destination
      
    참고

    SSH 데몬이 inactive 상태인 경우, firewalld 규칙은 적용되지 않지만 iptables 규칙은 적용됩니다.

    4. 라우팅 확인

    eth0에 대한 기본 경로(default route)가 설정되어 있지 않은 경우 접속이 이루어지지 않을 수 있습니다. 정적 경로(static route) 설정 상태를 확인해 주십시오.

    # route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         10.1.5.1        0.0.0.0         UG    0      0        0 eth0
    10.1.5.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
    

    5. 권한 이슈 확인

    SSH 설정 파일(/.ssh/config)의 설정에 따라 root 계정의 원격 접속이 차단되어 있을 수 있습니다. root 계정으로 접속할 수 없는 경우 일반 계정으로 접속을 시도해 주십시오.

    • 일반 계정이 없는 경우, 서버 접속 콘솔을 활성화한 후 root 계정으로 접속을 시도해 주십시오.

    Linux 서버(Ubuntu 18.04 기준)

    다음 절차에 따라 Ubuntu 18.04 운영 체제를 사용하는 Linux 서버의 접속 환경을 확인해 주십시오.

    1. SSH 데몬 상태 확인

    SSH 데몬 상태를 확인하는 방법은 다음과 같습니다.

    1. 다음 명령어를 입력해 SSH 데몬이 정상적으로 실행 중인 상태인지 확인해 주십시오.
      # systemctl status sshd
      
      server-ts-remote-lin-vpc_deamon_check_ubuntu
      • active (running)로 표시되는 경우 정상 실행 중입니다.
      • inactive로 표시되는 경우 SSH 데몬을 기동해 주십시오.
      • 데몬 기동 중 오류가 발생하는 경우 서버 로그를 확인해 SSH 데몬이 정상적으로 기동되도록 조치해 주십시오.
    2. 다음 명령어를 입력해 ssh 서비스가 22번 포트로 LISTEN하는지 확인해 주십시오.
      • 22번 포트는 Ncloud에서 제공하는 서버의 기본 설정값입니다. 다른 포트로 수정한 경우 해당 포트를 ACG에서 허용했는지 확인하고 해당 포트로 검색해 주십시오.
      # netstat -nap | grep ssh
      tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      982/sshd
      tcp        0      0 10.0.1.8:22             61.83.152.147:55020     ESTABLISHED 1593/sshd: root@pts
      
    3. 다음 명령어를 입력해 ssh 설정 파일(sshd_config)에서 PortListenAddress 항목에 설정된 부분이 있는지 확인해 주십시오.
      • 기본 설정은 주석 처리되어 있습니다.
      # vi /etc/ssh/sshd_config
      #       $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $
      
      # This is the sshd server system-wide configuration file.  See
      # sshd_config(5) for more information.
      
      # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
      
      # The strategy used for options in the default sshd_config shipped with
      # OpenSSH is to specify options with their default value where
      # possible, but leave them commented.  Uncommented options override the
      # default value.
      
      #Port 22
      #AddressFamily any
      #ListenAddress 0.0.0.0
      #ListenAddress ::
      

    2. hosts.deny 설정 상태 확인

    hosts.allow 파일과 hosts.deny 파일에 설정된 부분이 있는지 확인해 주십시오. hosts.allow 파일과 hosts.deny 파일은 특정 클라이언트에 대한 서비스 허용 및 차단을 제어합니다.

    • 기본 설정은 주석 처리되어 있습니다.
    # cat /etc/hosts.allow
    # /etc/hosts.allow: list of hosts that are allowed to access the system.
    #                   See the manual pages hosts_access(5) and hosts_options(5).
    #
    # Example:    ALL: LOCAL @some_netgroup
    #             ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
    #
    # If you're going to protect the portmapper use the name "rpcbind" for the
    # daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
    #
    
    # cat /etc/hosts.deny
    # /etc/hosts.deny: list of hosts that are _not_ allowed to access the system.
    #                  See the manual pages hosts_access(5) and hosts_options(5).
    #
    # Example:    ALL: some.host.name, .some.domain
    #             ALL EXCEPT in.fingerd: other.host.name, .other.domain
    #
    # If you're going to protect the portmapper use the name "rpcbind" for the
    # daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
    #
    # The PARANOID wildcard matches any host whose name does not match its
    # address.
    #
    # You may wish to enable this to ensure any programs that don't
    # validate looked up hostnames still leave understandable logs. In past
    # versions of Debian this has been the default.
    # ALL: PARANOID
    
    참고
    • /etc/hosts.allow, /etc/hosts.deny 파일은 tcp_wrappers만 제어하며, 규칙이 적용되는 순서는 다음과 같습니다.
      1. /etc/hosts.allow 파일에 정의된 호스트의 접속은 허용
      2. /etc/hosts.allow 파일에 정의되지 않고 /etc/hosts.deny 파일에 정의된 호스트의 접근은 거부
      3. 둘 중 한 파일에도 정의되지 호스트의 접속은 허용
    • tcp_wrappersssh, telnet, ftpxinetd가 관리하는 데몬들의 특정 서비스만 제어할 수 있습니다.

    3. 방화벽 확인

    방화벽 상태를 확인하는 방법은 다음과 같습니다.

    • ufw
      ufw에서 ssh 거부 규칙을 정의했는지 확인하고, ufw를 실행해야 하는 경우 ssh 거부 규칙을 제외해 주십시오(기본 설정: 규칙 없음).

      # ufw show raw
      ERROR: IPV4 (raw):
      Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
      Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
         pkts      bytes target     prot opt in     out     source               destination
      
    • iptables
      iptables.service가 설치된 경우 iptables에서 ssh 거부 규칙을 정의했는지 확인하고, ssh 거부 규칙을 제외해 주십시오(기본 설정: 규칙 없음).

      # iptables -L
      Chain INPUT (policy ACCEPT)
      target     prot opt source               destination
      
      Chain FORWARD (policy ACCEPT)
      target     prot opt source               destination
      
      Chain OUTPUT (policy ACCEPT)
      target     prot opt source               destination
      
    참고

    SSH 데몬이 inactive 상태인 경우, ufw 규칙은 적용되지 않지만 iptables 규칙은 적용됩니다.

    4. 라우팅 확인

    eth0에 대한 기본 경로(default route)가 설정되어 있지 않은 경우 접속이 이루어지지 않을 수 있습니다. 정적 경로(static route) 설정 상태를 확인해 주십시오.

    # route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         10.5.0.1        0.0.0.0         UG    0      0        0 eth0
    10.5.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
    

    5. 권한 이슈 확인

    SSH 설정 파일(/.ssh/config)의 설정에 따라 root 계정의 원격 접속이 차단되어 있을 수 있습니다. root 계정으로 접속할 수 없는 경우 일반 계정으로 접속을 시도해 주십시오.

    • 일반 계정이 없는 경우, 서버 접속 콘솔을 활성화한 후 root 계정으로 접속을 시도해 주십시오.

    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.