ssh 의 개인 설정 파일인 ~/.ssh/config 파일에 호스트 정보와 선호하는 인증 방식을 지정하며 여러 인증 방식을 사용할 경우 우선 순위가 높은 순서로 적어주면 됨. 아래는 publickey 인증을 시도하고 실패할 경우 password 인증을 사용.
~/.ssh/config
Host example
HostName example.com
User ec2-user
Port 10022
PreferredAuthentications publickey,keyboard-interactive,password
IdentityFile ~/.ssh/example/id_rsa
보안을 위해서는 공개키 방식만 사용하는 것이 좋지만 특정 사용자만 패스워드 방식이 필요할 경우 Match 키워드 사용해서 지정
/etc/ssh/sshd_config
PubkeyAuthentication
PasswordAuthentication no
# 접속을 허용할 사용자 계정
AllowUsers lesstif centos7 ec2-user
# lesstif, centos7 사용자만 암호 로그인 허용
Match User lesstif,centos7
PasswordAuthentication yes