Categories: LinuxTutorial

Enabling Password less ssh login

<div dir&equals;"ltr" style&equals;"text-align&colon; justify&semi;" trbidi&equals;"on"><b>Enabling Linux Automatic Password-less SSH Login<&sol;b><&sol;p>&NewLine;<p>&NewLine;Automatic passwrod-less ssh login can make our life easier&period; To enable this&comma; we need to copy our SSH public keys to the remote machines for automatic password-less login&period; We introduce two methods in this post&colon; using ssh-copy-id command and the manual way&period;<&sol;p>&NewLine;<p><b>Generate SSH key pair<&sol;b><&sol;p>&NewLine;<p>If you do not have a SSH private&sol;public key pair&comma; let’s generate one first&period;<br &sol;>&NewLine;<i><br &sol;>&NewLine;<&sol;i> <i>&dollar; ssh-keygen -t rsa<&sol;i><&sol;p>&NewLine;<p>By default on Linux&comma; the key pair is stored in ~&sol;&period;ssh &lpar;id&lowbar;rsa and id&lowbar;rsa&period;pub for private and public key&rpar;&period;<&sol;p>&NewLine;<p><b>Copy public SSH key to the remote machine<&sol;b><&sol;p>&NewLine;<p>You have two choices here&period; Unless that you can not use the ssh-copy-id method&comma; you can try the &OpenCurlyDoubleQuote;manual” way&period;<&sol;p>&NewLine;<p><b>The easiest way<&sol;b><&sol;p>&NewLine;<div align&equals;'center' id&equals;"ads-id"><&sol;div>&NewLine;<p>&NewLine;Let ssh-copy-id do it automatically&colon;<&sol;p>&NewLine;<p><i>&dollar; ssh-copy-id username&commat;remotemachine<&sol;i><&sol;p>&NewLine;<p>If you have multiple keys in your ~&sol;&period;ssh directory&comma; you may need to use -i key&lowbar;file to specify which key you will use&period;<&sol;p>&NewLine;<p><b>The manual way<&sol;b><&sol;p>&NewLine;<p>Copy the public SSH key to remote machine<&sol;p>&NewLine;<p><i>&dollar; scp &period;ssh&sol;id&lowbar;rsa&period;pub username&commat;remotemachine&colon;&sol;tmp&sol;<&sol;i><&sol;p>&NewLine;<p>Log on the remote machine<&sol;p>&NewLine;<p><i>&dollar; ssh username&commat;remotemachine<&sol;i><&sol;p>&NewLine;<p>Append your public SSH key to ~&sol;&period;ssh&sol;authorized&lowbar;keys<&sol;p>&NewLine;<p><i>&dollar; cp ~&sol;&period;ssh&sol;authorized&lowbar;keys ~&sol;&period;ssh&sol;authorized&lowbar;keys&period;bak &num; backing up before changing is a good habit<&sol;i><br &sol;>&NewLine;<i>&dollar; cat &sol;dev&sol;shm&sol;id&lowbar;rsa&period;pub &gt&semi;&gt&semi; ~&sol;&period;ssh&sol;authorized&lowbar;keys &num; append pub key to authorized keys list<&sol;i><&sol;p>&NewLine;<p>Make sure the mode of ~&sol;&period;ssh&sol;authorized&lowbar;keys is 755&colon;<&sol;p>&NewLine;<p><i>&dollar; chmod 755 ~&sol;&period;ssh&sol;authorized&lowbar;keys<&sol;i><&sol;p>&NewLine;<p><b>Possible Problems<&sol;b><br &sol;>&NewLine;<b><br &sol;>&NewLine;<&sol;b> <b>Home directory permission<&sol;b><&sol;p>&NewLine;<p>Check the home directory’s permission which may cause the key-based login fail &lpar;suppose the home directory is &sol;home&sol;zma&rpar;&colon;<&sol;p>&NewLine;<p><i>&num; chmod 700 &sol;home&sol;zma&sol;<&sol;i><&sol;p>&NewLine;<&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;what-is-hdfs&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;hadoop-confiuration&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '181'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

4 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

4 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

4 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

4 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

4 years ago