로그인없이 ssh 연결하기

Zdevowl·2021년 3월 9일
0

Linux

목록 보기
2/2

작업을 하다보면 ssh 없이 로그인을 수행해야 할 때가 있다. 그럴때는 ssh-keygen으로 키를 생성한 다음에 복사를 하면 된다.

하지만 여러대를 동시에 수행해야 한다면, 이 과정이 매우 번거로울 수도 있다. 아래 두가지 명령으로 손 쉽게 key를 배포할 수 있다.

ssh-keygen

ssh-keygen은 별다른 옵션없이 Next를 쭉 수행해줘도 되지만 아래 명령어를 이용하여 수행하면 Enter키 입력없이 바로 생성가능하다.

$ ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa

ssh-copy-id

앞서 만들어 준 키를 다른 머신에 배포하기 위해서는 ssh-copy-id를 이용하면 편리하다. 이 과정에서 처음 접속하는 유저의 경우 fingerprint를 요구한다. 귀찮지만 yes와 비밀번호 입력쯤은 수행하자.

$ ssh-copy-id -i ~/.ssh/id_rsa.pub <유저 명>@<IP or HostName>

수행예제)

$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@node01

# This is the default ansible 'hosts' file.
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/zdevowl/.ssh/id_rsa.pub"
The authenticity of host 'node01 (172.17.46.150)' can't be established.
ECDSA key fingerprint is SHA256:TaIzhom2AKkDedD7zQ2G66TEkZT+BF5/CrKN3hmwA/o.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

/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
root@node01's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@Node01'"
and check to make sure that only the key(s) you wanted were added.

누군가에게는 도움이 되길 바란다.

profile
공부하는 DB엔지니어

0개의 댓글