■ 비밀번호 없이 원격지 서버에 ssh를 통한 자동 로그인 방법을 알아보고자 한다. 먼저 root사용자로 로그인한 후 /etc/hosts파일을 아래와 같이 편집한다. 키 생성은 centos01서버에서 하며 centos01서버에서 각 원격지 서버(centos01, centos02, centos03, centos04, centos05)로 접속하는 것으로 가정한다. 일반 사용자의 계정 ID는 ‘nextman’이다.
bash# vi /etc/hosts 127.0.0.1 localhost ::1 localhost 192.168.192.128 centos01 192.168.192.130 centos02 192.168.192.133 centos03 192.168.192.132 centos04 192.168.192.131 centos05
■ ssh-keygen을 통해서 ssh개인키 및 공개키를 생성한다. 생성되면 일반사용자(nextman)계정의 .ssh디렉토리에 id_dsa(개인키), id_dsa.pub(공개키)가 생성된다. ls -al ~/.ssh/ 명령어를 통해서 확인 가능하다.
bash$ ssh-keygen -t dsa -P "" -f ~/.ssh/id_dsa $ ls -al ~/.ssh/ total 20 drwx------ 2 nextman nextman 4096 Feb 28 21:09 . drwx------. 5 nextman nextman 4096 Feb 28 16:26 .. -rw------- 1 nextman nextman 672 Feb 28 21:06 id_dsa -rw-r--r-- 1 nextman nextman 606 Feb 28 21:06 id_dsa.pub -rw-r--r-- 1 nextman nextman 597 Feb 28 21:09 known_hosts
■ ssh-copy-id ‘원격지 사용자ID@원격지 호스트 명’ 명령어를 통해서 각 원격지 서버(centos01, centos02, centos03, centos04, centos05)서버의 nextman 일반사용자의 공개키를 centos01로 복사한다.
bash$ ssh-copy-id nextman@centos01 /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 nextman@centos01's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'nextman@centos01'" and check to make sure that only the key(s) you wanted were added. bash$
■ 이제 각 원격지 서버에서 centos01서버에 모인 키를 다시 각 원격지 서버(centos01, centos02, centos03, centos04, centos05)로 scp명령어를 통해서 복사한다.
bash$ scp /home/nextman/.ssh/authorized_keys nextman@centos01:/home/nextman/.ssh/authorized_keys authorized_keys 100% 3030 3.0KB/s 00:00 bash$ scp /home/nextman/.ssh/authorized_keys nextman@centos02:/home/nextman/.ssh/authorized_keys authorized_keys 100% 3030 3.0KB/s 00:00 bash$ scp /home/nextman/.ssh/authorized_keys nextman@centos03:/home/nextman/.ssh/authorized_keys authorized_keys 100% 3030 3.0KB/s 00:00 bash$ scp /home/nextman/.ssh/authorized_keys nextman@centos04:/home/nextman/.ssh/authorized_keys authorized_keys 100% 3030 3.0KB/s 00:00 bash$ scp /home/nextman/.ssh/authorized_keys nextman@centos05:/home/nextman/.ssh/authorized_keys authorized_keys 100% 3030 3.0KB/s 00:00
■ ssh ‘호스트명’으로 접속하면 비밀번호 입력 요청없이 원격지 서버에 접속이 된다.
bash$ ssh centos02 Last login: Sun Feb 28 20:31:55 2016 from 192.168.192.1 bash$
- The uploaded file could not be moved to wp-content/uploads/2023/01. 2023년 1월 4일
- Linux 리눅스 디스크 사용량 확인 2022년 3월 23일
- 현재 서버의 포트가 열려있는지 확인하는 방법 2021년 12월 21일
- catalina.out 파일 최근 10000라인으로 자르기 2021년 4월 8일
- 리눅스 targ gzip을 이용한 디렉토리 압축 백업 2019년 4월 10일
- Window10에서 원격서버 포트 점검 2019년 1월 21일
- 리눅스 특정 문자열을 포함하는 파일 찾기 2019년 1월 8일
- Vmware에서 설치된 CentOS 7의 네트워크 설정 2017년 7월 24일
- AH00558: Set the ‘ServerName’ directive globally to suppress this message 2017년 4월 18일
- configure: error: You need a C++ compiler for C++ support. 2017년 4월 18일
- CentOS에서 컴파일할 때 no acceptable C compiler found in $PATH 에러 메세지 2017년 4월 18일
- XShell 단축키 모음 2016년 9월 5일
- ubuntu 일반 계정에서 SUDO를 이용하여 root 암호 변경하기 2016년 8월 30일
- yum으로 Linux man 설치 2016년 3월 14일
- vi 편집기 단어 바꾸기 2016년 3월 13일
- vi 편집기 환경 설정 2016년 3월 12일
- Linux sudo – 패스워드없이 root권한 명령 실행 2016년 3월 9일
- tar gzip bzip2 bz2 명령어 정리 2016년 3월 8일
- XShell 접속 리눅스 한글 2016년 3월 8일
- Sed 사용법 2016년 3월 7일
- Linux SCP 명령어 사용법 2016년 2월 29일
- VMware Clone 2016년 2월 25일
- CentOS7 ~/.bash_profile 예제 2015년 5월 2일
- CentOS7 Linux Tomcat7 자동시작 2015년 4월 8일
- CentOS7 Linux Subversion(SVN) 설치 2015년 4월 7일
- CentOS7 vsftpd 설치 2015년 3월 26일
- vsftpd 서비스 시작 메세지 – Redirecting to /bin/systemctl… 2015년 3월 17일
- [펌] yum 사용법 2015년 3월 17일
- Linux 일반 팁 2015년 3월 15일
- apache php mysql tomcat 연동 설치 2014년 10월 7일
- Vmware에 CentOS 설치 2014년 10월 1일
- VMWare 설치 2014년 9월 29일
- SSH 자동 로그인 2014년 9월 15일
- 리눅스 검색 tip 2014년 9월 15일
- 리눅스 아파치 프로세스 소유자 변경하기 2014년 9월 2일