Skip to content

Instantly share code, notes, and snippets.

@coolicer
Last active April 1, 2018 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolicer/680697fab1662e728c16583b5adf3327 to your computer and use it in GitHub Desktop.
Save coolicer/680697fab1662e728c16583b5adf3327 to your computer and use it in GitHub Desktop.
vps key login

[server]

  1. 生成SSH Key: ssh-keygen -t rsa

  2. 在vps上生成密钥对,公钥复制多一份叫authorized_keys

  3. 更改权限

[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh
  • 在这一步,把你自己机子的id_rsa.pub复制到authorized_keys,即可完成。
  1. 编辑 /etc/ssh/sshd_config 文件 进行如下设置:
RSAAuthentication yes
PubkeyAuthentication yes

#允许 root 登录

PermitRootLogin yes

你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

PasswordAuthentication no

重启ssh服务

[mac]

  1. 把服务器上生成的私钥下载下来,放在~/.ssh/文件夹里,然后vi ~/.ssh/config,在里面进行如下设置:
host vps
HostName 100.*.*.8
Port ***
User root
IdentityFile ~/.ssh/私钥
  1. 权限
chmod 700 ~/.ssh/私钥
  1. 登录
ssh vps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment