Linux SSH 암호 없이 로그인

1966 단어 Linux
요구사항: 모든 프로젝트를 한 서버에 배포
예를 들어 서버 A(192.168.0.1), B(192.168.0.2)가 있는데 각각 다른 응용을 배치하지만 서버를 왔다 갔다 전환하는 것이 비교적 번거로우므로 ssh 명령으로 A 서버에서 두 대의 서버를 배치할 수 있다.
단계:
  • 서버 A에 공개 키 - 개인 키 쌍 만들기
  • ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "  "
    

    주의: 키의 파일 이름은 id 이어야 합니다xxx, 여기 xxx는 - t 매개 변수가 지정한 키 형식입니다.예를 들어 키 형식이rsa라면 키 파일 이름은 id 이어야 합니다rsa.
    ssh-keygen이 설치되어 있지 않으면 설치하고 생성
    yum install -y ssh-keygen
    
  • 파일에 들어가서 만든 공개 키 - 개인 키 쌍
  • 보기
    [root@VM_0_14_centos ~]# cd ~/.ssh/
    [root@VM_0_14_centos .ssh]# ll
    total 12
    -rw------- 1 root root    0 Dec 17 10:00 authorized_keys
    -rw------- 1 root root 1679 Mar  5 13:55 id_rsa
    -rw-r--r-- 1 root root  393 Mar  5 13:55 id_rsa.pub
    -rw-r--r-- 1 root root  701 Mar  5 13:33 known_hosts
    
  • ssh-copy-id A의 공개 키를 B에게 보내는 기본 사용법은 ssh-copy-id입니다[email protected], ssh-copy-id 명령으로 원격 서버를 연결할 때 기본 포트는 22입니다. 물론 파일, 원격 호스트의 IP, 사용자와 포트를 지정할 수 있습니다.
  • [root@VM_0_14_centos .ssh]# pwd
    /root/.ssh
    [root@VM_0_14_centos .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22  [email protected]
    
    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
    /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
    [email protected]'s password: 
    
    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh -p '22' '[email protected]'"
    and check to make sure that only the key(s) you wanted were added.
    
    

    ssh-copy-id가 설치되어 있지 않으면 먼저 설치합니다
    yum install -y ssh-copy-id
    
  • 테스트
  • [root@VM_0_14_centos .ssh]#  ssh [email protected] "cd /usr/local ; ls"
    bin
    elfin
    etc
    games
    include
    lib
    lib64
    libexec
    sbin
    share
    src
    

    좋은 웹페이지 즐겨찾기