实验目的:在linux上通过ssh直接登录到windows系统上,不用密码
实验环境:在windows上安装cygwin,在linux 上通过ssh 连接到windows
Windows ip :10.1.165.1 linux ip : 10.1.151.111
配置前,由linux登录到windows需要密码
[yang@rac1 python]$ ssh -laaaa 10.1.165.1
aaaa@10.1.165.1's password:
Last login: Sun Jul 17 20:16:05 2011 from 127.0.0.1
aaaa@dfvkr-PC ~
$ dir
aaaa@dfvkr-PC ~
$ pwd
/home/aaaa
步骤:
1 在linux上通过ssh-keygen –t rsa 产生密钥
[yang@rac1 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yang/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yang/.ssh/id_rsa.
Your public key has been saved in /home/yang/.ssh/id_rsa.pub.
The key fingerprint is:
58:d9:4d:ad:04:08:ae:f7:5d:15:fd:36:58:b3:79:a2 yang@rac1
在home/yang目录下产生.ssh,修改其属性
[yang@rac1 ~]$ chmod 755 .ssh
进入该文件夹,查看生成的文件
[yang@rac1 .ssh]$ ls
id_rsa id_rsa.pub known_hosts
其中id_rsa 为私钥,id_rsa.pub 为公钥。我们需要将公钥拷贝到windows系统中cygwin显示的家目录,我的是/home/aaaa ,在此文件夹下建立 .ssh文件夹。(一下是在windows系统下的操作)
aaaa@dfvkr-PC ~
$ mkdir .ssh
aaaa@dfvkr-PC ~
$ ls -al
total 26
drwxr-xr-x+ 1 aaaa None 0 Jul 18 11:27 .
drwxrwxrwt+ 1 aaaa root 0 Jul 17 19:52 ..
-rw------- 1 aaaa None 309 Jul 18 10:24 .bash_history
-rwxr-xr-x 1 aaaa None 1103 Jul 17 17:28 .bash_profile
-rwxr-xr-x 1 aaaa None 5663 Jul 17 17:28 .bashrc
-rwxr-xr-x 1 aaaa None 1461 Jul 17 17:28 .inputrc
-rwxr-xr-x 1 aaaa None 792 Jul 17 17:28 .profile
drwxr-xr-x+ 1 aaaa None 0 Jul 18 11:27 .ssh
-rw-r--r-- 1 aaaa None 391 Jul 18 11:17 d:
然后拷贝linux上生成的公钥到.ssh目录下,并命名为authorized_keys
aaaa@dfvkr-PC ~
$ cd .ssh
aaaa@dfvkr-PC ~/.ssh
$ ls
authorized_keys
再次由linux登录到windows
[yang@rac1 python]$ ssh -laaaa 10.1.165.1
Last login: Mon Jul 18 11:28:20 2011 from 10.1.151.111
aaaa@dfvkr-PC ~
$ pwd
/home/aaaa
aaaa@dfvkr-PC ~
$ cd /
aaaa@dfvkr-PC /
$ ls
Cygwin.bat Cygwin.ico bin cygdrive dev etc home lib proc tmp usr var
aaaa@dfvkr-PC /
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22664653/viewspace-702461/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22664653/viewspace-702461/