Naver Cloud Platform 서버에 패스워드 입력 없이 로그인을 하는 방법에 대해 알아보겠습니다.
과정 요약
1. (PC) SSH 접속에 필요한 키 생성
2. (서버) 1번에서 생성한 키 등록
3. (서버) 키 기반 인증 허용
1. SSH 접속에 필요한 키 생성
SSH 접속에 필요한 키를 생성하는 방법은 아래의 블로그에 자세하게 기술되어 있습니다.
키 생성 방법 : http://webdir.tistory.com/200
Mac을 기준으로 작성했습니다.
### 키 생성 $ ssh-keygen -t rsa ### .ssh 디렉터리로 이동 $ cd .ssh ### 파일 확인 $ ls id_rsa id_rsa.pub ### id_rsa.pub 내용 확인, 이것을 등록할 것임 $ cat id_rsa.pub |
2. 생성한 키를 서버에 등록
Naver Cloud Platform 접속 방법
Linux 서버 : http://docs.ncloud.com/ko/compute/compute-3-1-v2.html
Windows 서버 : http://docs.ncloud.com/ko/compute/compute-3-2-v2.html
사용자 홈 디렉터리에 .ssh 디렉터리를 생성한 뒤, 그 안에 authorized_keys 파일을 만든다. 그 후, 1번에서 생성한 공개키를(id_rsa.pub) 넣어줍니다.
여기서는 새로운 계정을 만들어 이를 사용해 로그인하려고 합니다.
### 계정 생성, 설정 $ adduser carpfish $ passwd carpfish ### 계정 변경 (root --> carpfish), 종료는 exit 입력 $ su carpfish ### 홈 디렉터리로 이동 $ cd ~ ### 700권한으로 .ssh 디렉터리 생성 $ mkdir -m 700 .ssh ### .ssh 디렉터리로 이동 $ cd .ssh
### authorized_keys에 생성한 공개키 입력 $ echo 'your_public_key' >> authorized_keys ### authorized_keys 파일 권한 변경 $ chmod 600 authorized_keys ### 계정 변경 (carpfish --> root) $ exit |
3. 키 기반 인증 허용
/etc/ssh/sshd_config 파일의 내용을 확인한 뒤, 키 기반 인증을 허용합니다.
전체 내용에는 root 접속 방지, Rhost 무시 설정 등등 기본적인 보안을 설정한 sshd_config 파일 내용입니다.
전체 내용 부분을 전부 복사해 붙여넣기 하셔도 됩니다.
================== 키 기반 인증 허용 부분 ================== RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys ======================= 전체 내용 ======================= # $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 # HostKey for protocol version 1 #HostKey /etc/ssh/ssh_host_key # HostKeys for protocol version 2 HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 1h #ServerKeyBits 1024 # Ciphers and keying #RekeyLimit default none # Logging # obsoletes QuietMode and FascistLogging #SyslogFacility AUTH SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin no #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 RSAAuthentication yes PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #RhostsRSAAuthentication no # similar for protocol version 2 #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no PasswordAuthentication no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes # GSSAPI options GSSAPIAuthentication yes GSSAPICleanupCredentials no #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no #GSSAPIEnablek5users no # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several # problems. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no UsePrivilegeSeparation sandbox # Default for new installations. #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS # override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server |
SSH 데몬 재실행
$ systemctl restart sshd.service |
'Cloud' 카테고리의 다른 글
[Naver Cloud Platform] CentOS 7.3에 Hadoop 2.8.0 설치 (0) | 2017.06.25 |
---|
댓글