大数据,使用ssh-copy-id快速配置ssh无密码登录

使用下例中ssky-keygen和ssh-copy-id,仅需通过3个步骤的简单设置而无需输入密码就能登录远程Linux主机。

ssh-keygen创建公钥和密钥。

ssh-copy-id把本地主机的公钥复制到远程主机的authorized_keys文件上。

ssh-copy-id也会给远程主机的用户主目录(home)和~/.ssh,和~/.ssh/authorized_keys设置合适的权限。

步骤1:用ssh-key-gen在本地主机上创建公钥和密钥

ligh@local-host$ssh-keygen-trsa

Enterfileinwhichtosavethekey(/home/jsmith/.ssh/id_rsa):[Enterkey]

Enterpassphrase(emptyfornopassphrase):[Pressenterkey]

Entersamepassphraseagain:[Pessenterkey]

Youridentificationhasbeensavedin/home/jsmith/.ssh/id_rsa.

Yourpublickeyhasbeensavedin/home/jsmith/.ssh/id_rsa.pub.

Thekeyfingerprintis:33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9

ligh@local-host

步骤2:用ssh-copy-id把公钥复制到远程主机上

ligh@local-host$ssh-copy-id-i~/.ssh/[email protected]

ligh@remote-host‘spassword:

Nowtryloggingintothemachine,with―ssh?remote-host‘‖,andcheckin:

.ssh/authorized_keystomakesurewehaven‘taddedextrakeysthatyouweren‘texpecting.

[注:ssh-copy-id把密钥追加到远程主机的.ssh/authorized_key上.]

步骤3:直接登录远程主机

ligh@local-host$sshremote-host

Lastlogin:SunNov1617:22:332008from192.168.1.2

[注:SSH不会询问密码.]

ligh@remote-host$

[注:你现在已经登录到了远程主机上]

ssh

相关推荐