Last updated on
快捷ssh密钥登陆
快捷ssh密钥登陆
-
配置公钥和私钥
ssh-keygen -t rsa -C '-C这里用来添加你的注释信息'
-
传输公钥
scp ~/.ssh/id_rsa.pub <用户名>@<ip地址>:/home/id_rsa.pub
-
添加权限
mkdir -p ~/.ssh && chmod 700 ~/.ssh cat /home/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
-
本地配置用户
vim ~/.ssh/config # 模版如下 Host host_name HostName host_ip User root Port 22 IdentityFile ~/.ssh/id_rsa
-
SSH服务端
vim /etc/ssh/sshd_config
将前面的注释符删掉才能生效。
PermitRootLogin yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys # 只接收公钥认证 PasswordAuthentication no systemctl restart sshd