Chinaunix首页 | 论坛 | 博客
  • 博客访问: 484294
  • 博文数量: 158
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 904
  • 用 户 组: 普通用户
  • 注册时间: 2016-10-10 11:17
文章分类

全部博文(158)

文章存档

2018年(74)

2017年(84)

我的朋友

分类: 网络与安全

2018-08-16 16:57:47

经常需要登录到远程服务器作业,而且有时候还需跳转好几次才能到达目标机。有两种方式可以实现自动登录不输密码,从而节约宝贵的时间。本文转自培训机构-学领未来

场景一:从 windows 上登录远程 linux/unix 服务器

两种选择:

( 1 )采用 SecureCRT 的登录脚本实现自动登录。可以在 Options—>Session Options à Logon Actions 里启用 Automate logon 来实现自动登录。我目前主要以这种方式实现自动化的登录,用户名和密码都不需要输入,只需事先配置好好就可以了。

( 2 )通过 Cygwin 实现类 linux 化的方式配置密钥验证的方式进行登录。后面会以 linux à linux 的场景介绍这种方式。

 

场景二:从 linux/unix à linux/unix

例子: 10.56.136.206 想要登录到 10.56.255.98 ,登录时不需要输入密码。

       第一步:生成密钥

       登录到 10.56.136.206 上去,执行 ” ssh-keygen -t rsa” 命令,在提示输入时全部以回车跳过即可。如下 :

[root@app6 ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

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:

95:44:53:15:1e:5f:87:52:66:04:71:23:ba:8b:61:d7 root@app6.mgmt

[root@app6 ~]#

执行完之后, /root/.ssh 目录下会产生两个文件。如下:

[root@app6 .ssh]# pwd

/root/.ssh

[root@app6 .ssh]# ls -lrt

total 10

-rw-r--r-- 1 root root 6771 Nov 15 15:17 known_hosts

-rw-r--r-- 1 root root  396 Nov 15 17:18 id_rsa.pub

-rw------- 1 root root 1675 Nov 15 17:18 id_rsa

[root@app6 .ssh]#

 

   第二步:将密钥拷贝至目标机器 10.56.255.98

   进入 /root/.ssh 目录执行拷贝:

[root@app6 .ssh]# ssh-copy-id -i id_rsa.pub root@10.56.255.98

10

root@10.56.255.98's password:

Now try logging into the machine, with "ssh 'root@10.56.255.98'", and check in:

 

  .ssh/authorized_keys

 

to make sure we haven't added extra keys that you weren't expecting.

 

此时再输入 ” ssh 10.56.255.98” 就不需要输入密码就可以了。

[root@app6 .ssh]# ssh 10.56.255.98

Last login: Mon Nov 15 16:54:44 2010 from 10.56.136.206

[root ~]#

 

阅读(1724) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~