ssh 远程登录过去不用密码 ssh-keygen -t rsa

我在另一台机器上拥有adinm用户的sudo权限,并且可以输入密码登录到Host上我的目录下。

目标是可以不输入密码就可以登录到目标机器的admin下

如果目标机器的/home/admin下没有  .ssh目录

HostA ----->HostB,guest在HostB拥有admin的sudo权限

1 登录到HostB,在HostB的/home/admin目录下 执行 ssh-keygen -t rsa

[shuohai.lhl@test2 ~]$ sudo su admin
[admin@test2 shuohai.lhl]$ cd /home/admin
[admin@test2 ~]$ ssh-keygen -t rsa           
Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin/.ssh/id_rsa): 
Created directory '/home/admin/.ssh'.
Enter passphrase (<span style="color:#ff0000;">empty for no passphrase</span>): #不需要输入密码
Enter same passphrase again: 
Your identification has been saved in /home/admin/.ssh/id_rsa.
Your public key has been saved in /home/admin/.ssh/id_rsa.pub.
The key fingerprint is:
0e:4d:23:38:73:f6:3e:9a:bb:1b:43:fa:55:f7:3f:7a [email protected]
-t 表示加密类型,用rsa;执行完创建了隐藏文件夹.ssh

2  生成两个文件id_rsa,id_rsa.pub,

[admin@test2 ~]$ cd .ssh
[admin@test2 .ssh]$ ll -a
total 16
drwx------ 2 admin admin 4096 Jan 28 19:44 .
drwx------ 7 admin admin 4096 Jan 28 19:44 ..
-rw------- 1 admin admin 1675 Jan 28 19:44 id_rsa
-rw-r--r-- 1 admin admin  400 Jan 28 19:44 id_rsa.pub


3 创建一个文件,命名为 authorized_keys,内容是 HostA ~/.ssh/id_rsa.pub的文件内容

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzYmUCTNv2GyPR5gHtiD9celnHHzMBrk+xshTKfAVRW9KYPGNB6yw/f2HYimKdlboQiuBy3AJrmnh97tOS45BfC4pIBGWxwgOh+3hUokzWe7cL7WS8XWy/Tq+8NaPfUd5yqOyekxxiqyKVice2GMakVPwTpSLNxmrzmKsjJYZ5MlHLFIecH0axpUGPOj/nGM/Df9/6WtGWbg+LTU58sNEOb/OZjgUKf9+y/rkUQNR1B8Hb+1DPk3SIR2MkSXZBOxtR08XQPRd2I2Ts9p19keJhXzhxJxCv+JEU4bQeMWGiyxOYYHX2H+yPhe7KfEOkMC/dqrqll92ZFtu80P/dECvFQ== [email protected]


4 保存,退出HostB,到HostA上执行 

ssh admin@HostB
就可以不输密码直接登陆了




你可能感兴趣的:(ssh 远程登录过去不用密码 ssh-keygen -t rsa)