使用限制SSH密钥对仅支持Linux系统创建。 创建SSH密钥操作步骤1. 使用VNC或服务器账号密码连接Linux实例。 2. 打开终端,输入以下指令,查看是否已经生成SSH秘钥。 1. ls -al ~/.ssh 2. # Lists the files in your .ssh directory, if they exist
如果有文件id_rsa.pub 或 id_dsa.pub 说明已经创建过SSH密钥,导入即可。 3. 生成新的SSH密钥。 在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令: 0. [root@host ~]$ ssh-keygen <== 建立密钥对 1. Generating public/private rsa key pair. 2. Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter 3. Created directory '/root/.ssh'. 4. Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空 5. Enter same passphrase again: <== 再输入一遍密钥锁码 6. Your identification has been saved in /root/.ssh/id_rsa. <== 私钥 7. Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥 8. The key fingerprint is: xxxxxxx
4. 创建完成,安装公钥。 输入以下命令,在服务器上安装公钥: 0. [root@host ~]$ cd .ssh 1. [root@host .ssh]$ cat id_rsa.pub >> authorized_keys 如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确: 2. [root@host .ssh]$ chmod 600 authorized_keys 3. [root@host .ssh]$ chmod 700 ~/.ssh 5. 设置SSH,打开密钥登录。 编辑 /etc/ssh/sshd_config 文件,进行如下设置: 0. RSAAuthentication yes 1. PubkeyAuthentication yes 另外,请留意 root 用户能否通过 SSH 登录: 2. PermitRootLogin yes 当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录: 3. PasswordAuthentication no 最后,重启 SSH 服务: 4. [root@host .ssh]$ service sshd restart
|