1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > windows登录linux免密码 Windows使用SSH Secure Shell实现免密码登录Linux的方法以

windows登录linux免密码 Windows使用SSH Secure Shell实现免密码登录Linux的方法以

时间:2019-08-05 07:59:51

相关推荐

windows登录linux免密码 Windows使用SSH Secure Shell实现免密码登录Linux的方法以

1.环境信息

SSH Secure Shell Client所在的操作系统:

Windows7

Linux服务器以及SSH的版本:

[hadoop@gpmaster ~]$ cat /etc/redhat-release

Red HatEnterprise Linux Server release 6.0 (Santiago)

[hadoop@gpmaster ~]$ ssh -V

OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar

默认各种版本的Linux或Unix操作系统都会安装好SSH服务的。

2.Windows 7上面安装SSH客户端

具体的下载地址为:

下载的文件是一个exe可执行文件。SSH Secure Shell安装很简单,和一般windows软件安装没有区别,这里就不介绍了。

3.免密码登录的原理

大家如果熟悉Linux的话,应该知道SSH服务中有公钥和私钥的概念。

Public Key是指公钥,而Private Key是指私钥。

认证的过程如下:

Public Key对数据进行加密而且只能用于加密,Private Key也只能对所匹配的Public Key加密过的信息进行解密。

如果我们把Windows上面生成的Public Key放到Linux服务器上指定用户家目录下面的.ssh目录中,并添加公钥内容到.ssh目录下面的authorized_keys文件。

如果我们开始从Windows(客户端)上面通过ssh方式远程Linux(服务器)时,此时客户端软件就会向服务器发出请求,请求用密匙进行安全验证。服务器收到请求之后,先在该服务器上的主目录下寻找公匙,然后把它和发送过来的公匙进行比较。如果两个密匙一致,服务器就用公匙加密“质询”并把它发送给客户端软件。客户端软件收到“质询”之后就可以用私匙解密再把它发送给服务器,此时因为密钥能匹配上,所以可以直接登录到Linux服务器。

4.在Windows本机上生成密钥

首先找到SSH SecureShell的安装路径,比如我安装的路径指定为:

D:\SSHCommunications Security\SSH Secure Shell

我们可以通过dos命令在生成密钥,如下:

步骤一,进入dos界面

C:\Users\Administrator>

步骤二,进入SSH SecureShell安装路径:

C:\Users\Administrator>D:

D:\>cd D:\SSH Communications Security\SSH Secure Shell

D:\SSHCommunications Security\SSH Secure Shell>

步骤三,执行生成密钥的命令:

D:\SSHCommunications Security\SSH Secure Shell>ssh-keygen2-t rsa

注释:我们这里使用rsa的密钥,默认是2048bit(位),同样我们也可以使用dsa方式的密钥。

在执行ssh-keygen2 -t rsa生成密钥对时,会提示你输入Passphrase的值,我们要求免密码登录服务器,所以直接回车。命令执行过程如下:

D:\SSH Communications Security\SSH Secure Shell>ssh-keygen2 -t rsa

Generating 2048-bit rsa key pair

3 o..oOo.oOo.o

Key generated.

2048-bit rsa, Administrator@USER-0414LO, Wed Feb 17 13:34:16

Passphrase :

Again :

Key is stored with NULL passphrase.

(You can ignorethe following warning if you are generating hostkeys.)

This is notrecommended.

Don't do thisunless you know what you're doing.

If file systemprotections fail (someone can access the keyfile),

or if thesuper-user is malicious, your key can be used without

the decipheringeffort.

Private key saved to C:/Users/Administrator/ApplicationData/SSH/UserKeys/id_rsa

_2048_a

Public key saved to C:/Users/Administrator/ApplicationData/SSH/UserKeys/id_rsa_

2048_a.pub

根据提示知道了生成的密钥对的路径,但是经过我实际查找,我的windows环境的密钥对位于:C:\Users\Administrator\AppData\Roaming\SSH\UserKeys下面。

5.使用SSH客户端免密码登录到远程Linux服务器的hadoop用户下

1)我们先用输入密码的方式登录到Linux服务器的hadoop用户下,然后在hadoop用户的家目录下面创建.ssh用户(如果已经存在就不需要创建):

[hadoop@gpmaster.ssh]$ pwd

/home/hadoop/.ssh

并在/home/hadoop/.ssh下面创建authorized_keys文件(如果已经存在就不需要创建)

2)然后我们将Windows的C:\Users\Administrator\AppData\Roaming\SSH\UserKeys目录下的id_rsa_2048_a.pub文件上传到Linux服务器的hadoop用户的/home/hadoop/.ssh目录下面。

3)如果是Linux之间信任关系,就直接将公钥的内容添加到authorized_keys文件中即可。但是这里因为我们的公钥是在Windows上面生成的,Linux的Openssh不识别,所以需要进行转换后再追加到authorized_keys中:

[hadoop@gpmaster.ssh]$ ssh-keygen -i -f id_rsa_2048_a.pub >>authorized_keys

4)退出之前使用密码登录的SSH Secure Shell客户端,然后重新登录并在登录认证状态栏中选择Public Key方式,这样就可以免密码登录了。

6.使用SSH Secure Shell客户端自带的scp2命令下载Linux服务器的文件

D:\SSH Communications Security\SSHSecure Shell>scp2.exe -r -d hadoop@192.168.1.128:/home/hadoop/testhivedataD:\test\

.000000_0.crc | 12B |12B/s | TOC: 00:00:01 | 100%

000000_0 | 96B |96B/s | TOC: 00:00:01 | 100%

datacity.txt | 95kB |95kB/s | TOC: 00:00:01 | 100%

可以看出远程拷贝也不需要输入密码。

windows登录linux免密码 Windows使用SSH Secure Shell实现免密码登录Linux的方法以及使用scp2命令免密码下载文件...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。