Computer Science/Server

SSH Key 으로 서버 접속하기

귀찮은 개발자 2024. 2. 11. 13:29

아래와 같이 ~/.ssh/config 경로에 ssh config 파일을 작성하여 서버에 쉽게 접속할 수 있다. 

Host server1
	Hostname ~~~.~~~.~~~.~~~
	User ubuntu
	Port 22
	IdentityFile ~/.ssh/id_rsa_1Password

Host server1
	Hostname ~~~.~~~.~~~.~~~
	User ubuntu
	Port 22
	IdentityFile ~/.ssh/id_rsa_1Password

Host *
	HostkeyAlgorithms +ssh-rsa
	PubkeyAcceptedAlgorithms +ssh-rsa

Host *
	IdentityAgent "~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock"

 

헌데 Config 작성까지 마쳤으면 서버에 Public Key 를 등록하여 마무리를 해야한다. 

 

echo 퍼블릭키 >> ~/.ssh/authorized_keys

 

참고로 Github 는 보안상의 이유로 DSA 키(ssh-dss)를 지원하지 않는다고 하니 RSA나 DSA에 비해 성능이 뛰어난 ED25519 을 사용하여 만드는 것이 좋다. 

 

여기서 생성한 키를 로컬의 ~/.ssh/config 와 서버의 ~/.ssh/authorized_keys 에 등록해 주면 된다. 

ssh-keygen -t ed25519 -C "email@example.com"