手机版
你好,游客 登录 注册
背景:
阅读新闻

SSH无需密码登录Linux服务器

[日期:2015-05-21] 来源:Linux社区  作者:kevalin [字体:大 中 小]

使用下例中ssky-keygen和ssh-copy-id,仅需通过3个步骤的简单设置而无需输入密码就能登录远程Linux主机。
ssh-keygen 创建公钥和密钥。
ssh-copy-id 把本地主机的公钥复制到远程主机的authorized_keys文件上。
ssh-copy-id 也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh/authorized_keys设置合适的权限 。

步骤1: 用 ssh-key-gen 在本地主机上创建公钥和密钥

linuxidc@local-host$ ssh-keygen -t rsa
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key] 
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub. 
The key fingerprint is: 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 
linuxidc@local-host

步骤2: 用 ssh-copy-id 把公钥复制到远程主机上

linuxidc@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3
linuxidc@remote-host‘s password:
Now try logging into the machine, with ―ssh ?remote-host‘‖, and check in: 
.ssh/authorized_keys to make sure we haven‘t added extra keys that you weren‘t expecting.

[注: ssh-copy-id 把密钥追加到远程主机的 .ssh/authorized_key 上.]

linuxidc@local-host$ ssh remote-host 
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2 
linuxidc@remote-host$ 

[注: 你现在已经登录到了远程主机上]

提高Ubuntu的SSH登陆认证速度的办法 http://www.linuxidc.com/Linux/2014-09/106810.htm

开启SSH服务让Android手机远程访问 Ubuntu 14.04  http://www.linuxidc.com/Linux/2014-09/106809.htm

如何为Linux系统中的SSH添加双重认证 http://www.linuxidc.com/Linux/2014-08/105998.htm

在 Linux 中为非 SSH 用户配置 SFTP 环境 http://www.linuxidc.com/Linux/2014-08/105865.htm

Linux 上SSH 服务的配置和管理 http://www.linuxidc.com/Linux/2014-06/103627.htm

SSH入门学习基础教程 http://www.linuxidc.com/Linux/2014-06/103008.htm

SSH免密码登录详解  http://www.linuxidc.com/Linux/2015-03/114709.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-05/117794.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款