SSH-KeyGen 的用法 【转载】
2016-04-15 21:55
267 查看
SSH-KeyGen 的用法
secureCrt通过密钥登录做法:
1、登录A机器
2、ssh-keygen -t [rsa|dsa],将会生成密钥文件和私钥文件 id_rsa,id_rsa.pub或id_dsa,id_dsa.pub
3、将 .pub 文件复制到B机器的 .ssh 目录, 并 cat id_dsa.pub >> ~/.ssh/authorized_keys
4、大功告成,从A机器登录B机器的目标账户,不再需要密码了;
1. 制作密钥对
首先在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令:
[root@host ~]$ ssh-keygen <== 建立密钥对 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空 Enter same passphrase again: <== 再输入一遍密钥锁码 Your identification has been saved in /root/.ssh/id_rsa. <== 私钥 Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥 The key fingerprint is: 0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。
现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。
2. 在服务器上安装公钥
键入以下命令,在服务器上安装公钥:
[root@host ~]$ cd .ssh [root@host .ssh]$ cat id_rsa.pub >> authorized_keys 如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确: [root@host .ssh]$ chmod 600 authorized_keys [root@host .ssh]$ chmod 700 ~/.ssh
3. 设置 SSH,打开密钥登录功能
编辑 /etc/ssh/sshd_config 文件,进行如下设置:
RSAAuthentication yes PubkeyAuthentication yes 另外,请留意 root 用户能否通过 SSH 登录,默认为yes: PermitRootLogin yes 当我们完成全部设置并以密钥方式登录成功后,可以禁用密码登录。这里我们先不禁用,先允许密码登陆 PasswordAuthentication yes 最后,重启 SSH 服务: [root@host .ssh]$ service sshd restart
相关文章推荐
- bzoj4531 [Bjoi2014]路径
- Mac下 PostgreSQL 的安装与使用
- 怎样简单保存下载 Windows 10 随机聚焦锁屏壁纸?
- The OAuth 2.0 Authorization Framework
- 开发笔记-简单渐变动画的实现
- display:inline、block、inline-block的区别
- CodeForces 622D Optimal Number Permutation(构造)
- 【LeetCode】108. Convert Sorted Array to Binary Search Tree 解法及注释,分治法,递归
- Linux 安装apr
- 测试步骤
- JAVA 自定义泛型
- npm模块corn源码分析
- modelsim-win64-10.1c 下载、安装、破解全攻略
- 极大极小过程题集
- bzoj4533 [BeiJing2014 WinterCamp] 数据
- SQL Server 与 Entity Framework 级联删除
- ubuntu运行sh脚本sudo自动输入密码
- Linux 安装apr-util
- poj 1742(好题,楼天城男人八题,混合背包)
- 普通身份运行Tomcat