Skip to content

Instantly share code, notes, and snippets.

@gist4ray
Last active July 4, 2021 12:46
Show Gist options
  • Save gist4ray/a0bee33682b0cb26d09252637d5decce to your computer and use it in GitHub Desktop.
Save gist4ray/a0bee33682b0cb26d09252637d5decce to your computer and use it in GitHub Desktop.
ssh密钥配置

配置ssh服务器和账号

$ cd ~/.ssh/
$ vi config

config内容如下,一个Host就是一个主机

Host test1
    HostName 121.43.170.99
    Port 22
    User root

Host demo
    HostName 12.34.56.78
    Port 22
    User root

生成密钥对

$ ssh-keygen -t rsa

$ ls -al

可以看到,在.ssh目录下多了两个文件id_rsa和id_rsa.pub,私钥和公钥

复制公钥

$ cat id_rsa.pub

主机配置

$ cd ~/.ssh
$ vi authorized_keys

cd /root/.ssh
touch authorized_keys
cat /root/.ssh/id_rsa.pub >> authorized_keys


sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
service sshd restart

重新登录

$ ssh test1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment