您的位置:首页 > 其它

SSH Passwordless Login Using SSH Keygen in 5 Easy Steps

2014-04-22 15:40 435 查看
SSH(SecureSHELL)isanopensourceandmosttrustednetworkprotocolthatisusedtologinintoremoteserversforexecutionofcommandsandprograms.Itisalsousedtotransferfilesfromonecomputertoanothercomputeroverthe
networkusingsecurecopy(
SCP)Protocol.

Inthisarticlewewillshowyouhowtosetuppassword-lessloginusing
sshkeystoconnecttoremoteLinuxserverswithoutenteringpassword.UsingPassword-lessloginwithSSHkeyswillincreasethetrustbetweentwo
Linuxserversforeasyfilesynchronizationortransfer.

IfyouaredealingwithnumberofLinuxremoteservers,then
SSHPassword-lessloginisoneofthebestwaytoautomatetaskssuchasautomaticbackupswithscripts,synchronizationfilesusingscpandremotecommandexecution.

InthisexamplewewillsetupSSHpassword-lessautomaticloginfromserver192.168.1.1asuser
tecmintto192.168.1.2withusersheena.

Step1:CreateAuthenticationSSH-KegenKeyson–(192.168.1.1)

Firstloginintoserver192.168.1.1withuser
tecmintandgenerateapairofpublickeysusingfollowingcommand.

[tecmint@tecmint.com~]$ssh-keygen-trsa

Generatingpublic/privatersakeypair.

Enterfileinwhichtosavethekey(/home/tecmint/.ssh/id_rsa):[Pressenterkey]

Createddirectory'/home/tecmint/.ssh'.

Enterpassphrase(emptyfornopassphrase):[Pressenterkey]

Entersamepassphraseagain:[Pressenterkey]

Youridentificationhasbeensavedin/home/tecmint/.ssh/id_rsa.

Yourpublickeyhasbeensavedin/home/tecmint/.ssh/id_rsa.pub.

Thekeyfingerprintis:

af:bc:25:72:d4:04:65:d9:5d:11:f0:eb:1d:89:50:4ctecmint@tecmint.com

Thekey'srandomartimageis:

+--[RSA2048]----+

|..oooE.++|

|o.o.o|

|...|

|o..o|

|S..+|

|...o|

|.oo..|

|++|

|+.|

+-----------------+

Step2:Create.sshDirectoryon–192.168.1.2

UseSSHfromserver[b]192.168.1.1toconnectserver
192.168.1.2
usingsheenaasuserandcreate
.sshdirectoryunderit,usingfollowingcommand.[/b]

[tecmint@tecmint~]$sshsheena@192.168.1.2mkdir-p.ssh

Theauthenticityofhost'192.168.1.2(192.168.1.2)'can'tbeestablished.

RSAkeyfingerprintisd6:53:94:43:b3:cf:d7:e2:b0:0d:50:7b:17:32:29:2a.

Areyousureyouwanttocontinueconnecting(yes/no)?yes

Warning:Permanentlyadded'192.168.1.2'(RSA)tothelistofknownhosts.

sheena@192.168.1.2'spassword:[[b]EnterYourPasswordHere][/b]



Step3:UploadGeneratedPublicKeysto–192.168.1.2

UseSSHfromserver192.168.1.1anduploadnewgeneratedpublickey(id_rsa.pub)onserver
192.168.1.2undersheena‘s.sshdirectoryasafilename
authorized_keys.

[tecmint@tecmint~]$cat.ssh/id_rsa.pub|sshsheena@192.168.1.2'cat>>.ssh/authorized_keys'

sheena@192.168.1.2'spassword:[EnterYourPasswordHere]



Step4:SetPermissionson–192.168.1.2

DuetodifferentSSHversionsonservers,weneedtosetpermissionson.sshdirectoryandauthorized_keysfile.

[tecmint@tecmint~]$sshsheena@192.168.1.2"chmod700.ssh;chmod640.ssh/authorized_keys"

sheena@192.168.1.2'spassword:[EnterYourPasswordHere]



Step5:Loginfrom192.168.1.1to192.168.1.2ServerwithoutPassword

Fromnowonwardsyoucanloginto192.168.1.2assheenauserfromserver
192.168.1.1astecmintuserwithoutpassword.

[tecmint@tecmint~]$sshsheena@192.168.1.2


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐