• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
孙龙 程序员
少时总觉为人易,华年方知立业难
博客园    首页    新随笔    联系   管理    订阅  订阅
ssh免密码+别名登录

免密码登录

    1. 首先创建本机的公钥和私钥,使用命令ssh-keygen。 
      默认生成的公钥名为id_rsa.pub ,私钥名为id_rsa。当然也可以通过参数 -t 来指定名称,如:ssh-keygen -t rsa 一路回车即可。

  

可以使用ls ~/.ssh/命令来查看生成的公钥和私钥

进入该目录ls就会发现有两个文件,id_rsa和id_rsa.pub,前者为私钥,后者为公钥

[root@localhost ~]# cd ~/.ssh/
[root@localhost .ssh]# ls
authorized_keys config id_rsa id_rsa.pub
[root@localhost .ssh]#

  

[root@localhost .ssh]# ll
总用量 16
-rw------- 1 root root  819 8月  29 13:40 authorized_keys
-rw-r--r-- 1 root root   66 8月  29 13:32 config
-rw------- 1 root root 1679 8月  29 13:38 id_rsa
-rw-r--r-- 1 root root  408 8月  29 13:38 id_rsa.pub

 

没有authorized_keys就新建一个文件

远程服务器执行:

[root@localhost .ssh]# cat  id_rsa.pub   >> authorized_keys

[root@localhost .ssh]# chmod 600 authorized_keys

把本地(windows)服务器的公钥id_rsa.pub复制追到到远程服务器的authorized_keys

 

别名登录

比如:window电脑上链接远程服务器

C:\Users\Administrator\.ssh {svn}
$ ls
config id_rsa id_rsa.pub known_hosts

  

使用 vim ~/.ssh/config命令编辑文件,添加如下内容:

Host admin
HostName 192.168.200.12
Port 22
User root
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

  

使用ssh <Host>登录目的主机,这里使用ssh Server_12就相当于执行ssh root@192.168.200.12。 
注释: 
HostName 指定登录的主机名或IP地址 
Port 指定登录的端口号 
User 登录用户名 
IdentityFile 登录的公钥文件 
IdentitiesOnly 只接受SSH key 登录

 

本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/articles/9589083.html

posted on 2018-09-04 22:53  孙龙-程序员  阅读(229)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3