Skip to content

Instantly share code, notes, and snippets.

@wangwy
Last active August 29, 2015 14:05
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 wangwy/fc734e320d6ee3023b5a to your computer and use it in GitHub Desktop.
Save wangwy/fc734e320d6ee3023b5a to your computer and use it in GitHub Desktop.
第一步:生成密钥文件
$ ssh-keygen
(该命令会在用户主目录下创建.ssh目录,并在其中创建两个文件:
id_rsa: 私钥文件,要妥善保管不要泄漏
id_rsa.pub: 公钥文件,可以公开)
第二步:将公钥远程加入服务器的公钥认证列表中
$ ssh-copy-id -i .ssh/id_rsa.pub <user>@<server>
(如果用户的公钥直接在服务器上,直接将文件追加到authorized_keys文件中:
$cat user.pub >> ~anonymous/.ssh/authorized_keys)
第三步:禁止用户用密码方式登录
修改一下服务器的配置文件/etc/sshd/sshd_config PasswordAuthentication no 修改完后要重启sshd服务。
注意: .ssh 目录的权限必须是0700 .ssh/authorized_keys 文件权限必须是0600 否则公钥认证不会生效
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment