<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khoa DINH</title>
    <description>The latest articles on DEV Community by Khoa DINH (@ddkhoa_blogging).</description>
    <link>https://dev.to/ddkhoa_blogging</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F775125%2Fbfbd2dce-7efd-408c-a487-ee90e14f7e82.png</url>
      <title>DEV Community: Khoa DINH</title>
      <link>https://dev.to/ddkhoa_blogging</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ddkhoa_blogging"/>
    <language>en</language>
    <item>
      <title>In 2022, I Found a Simple Method to Accomplish My Side Projects</title>
      <dc:creator>Khoa DINH</dc:creator>
      <pubDate>Sun, 18 Dec 2022 17:42:11 +0000</pubDate>
      <link>https://dev.to/ddkhoa_blogging/in-2022-i-found-a-simple-method-to-accomplish-my-side-projects-3ek5</link>
      <guid>https://dev.to/ddkhoa_blogging/in-2022-i-found-a-simple-method-to-accomplish-my-side-projects-3ek5</guid>
      <description>&lt;h3&gt;
  
  
  Let personal projects be fun instead of a burden
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F12032%2F0%2ASR4JLQeGEJTreXHl" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F12032%2F0%2ASR4JLQeGEJTreXHl" alt="Photo by [Felipe Furtado](https://unsplash.com/@furtado?utm_source=medium&amp;amp;utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral)" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How I failed to finish my project
&lt;/h2&gt;

&lt;p&gt;Like other developers, I love building applications. I spend my free time coding because it is fun. In addition, doing projects is my preferred method to improve my coding skills.&lt;/p&gt;

&lt;p&gt;However, while starting a new project is always exciting, finishing one is challenging. I faced many problems in completing my applications.&lt;/p&gt;

&lt;p&gt;Many factors can prevent us from finishing a project, including a lack of clear goals or direction, distraction, perfectionism, and so on. In my case, I was frequently distracted in the middle of my projects. Here is what is in my head, in order:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Okay, we start a project. We will build an elegant application. Let's implement a scalable architecture with clean code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Ah, I have new ideas about it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I will add this new functionality. It’s cool.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I better use this library rather than the current.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Oh… I should not do this in the first place. It is not what I want. Let’s change the code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I wasted too much time switching between this and that.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Oh… the project looks like a mess… I cannot continue… I want a cleaner project from the beginning.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And I abandoned my projects &lt;strong&gt;many&lt;/strong&gt; times.&lt;/p&gt;

&lt;h2&gt;
  
  
  My solution
&lt;/h2&gt;

&lt;p&gt;Last year, I started to write articles on Medium. At first, I wrote non-technical articles. Then, while working on my n-th side projects, I considered writing a tutorial on Medium.&lt;/p&gt;

&lt;p&gt;And that idea changed the game.&lt;/p&gt;

&lt;p&gt;Because I enjoy posting my content, I have the motivation to finish the project and write articles. My project also has a virtual audience.&lt;/p&gt;

&lt;p&gt;The objective became clear. I eliminated all fancy but irrelevant ideas. I made an effort to keep the application as simple as possible. Because if it was complicated, I couldn't explain it in the tutorial. It didn't take me a lot of time to choose a library. I use whatever does the job and is well-documented.&lt;/p&gt;

&lt;p&gt;And that how I finish this project.&lt;br&gt;
&lt;a href="https://javascript.plainenglish.io/use-adminjs-to-quickly-build-an-administration-web-app-1a6421fe7864" rel="noopener noreferrer"&gt;&lt;strong&gt;Use AdminJS to Quickly Build an Administration Web App&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can divide the project into several articles if it does not fit into one. Below are some projects that I finished recently, following the same principle.&lt;br&gt;
&lt;a href="https://javascript.plainenglish.io/web-crawler-javascript-these-easy-steps-help-me-get-medium-articles-data-3b9e9e76594" rel="noopener noreferrer"&gt;&lt;strong&gt;Web Crawler with JavaScript- These Easy Steps Help Me Get Medium Articles’ Data&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@ddkhoa.blogging/of-curiosity-i-analyzed-180-000-articles-on-medium-53f359ecdecc" rel="noopener noreferrer"&gt;&lt;strong&gt;Of curiosity, I analyzed ~180 000 articles on Medium&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;More advantages&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Besides the motivation to finish the project, sharing the result on Medium has additional non-negligible advantages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learning — the second time
&lt;/h3&gt;

&lt;p&gt;When I write the tutorial, I think about the audience and find a straightforward way to explain the concept. The process of making things simple helps me better understand my code.&lt;/p&gt;

&lt;p&gt;Learning by doing is one of the most effective methods. Now we combine it with explaining and teaching to others. Is it the most powerful combination for learning?&lt;/p&gt;

&lt;h3&gt;
  
  
  Save it for future
&lt;/h3&gt;

&lt;p&gt;Create a tutorial and post it on Medium or your blog, and you will have it forever. You can consult it anytime in the future when you need it.&lt;/p&gt;

&lt;h3&gt;
  
  
  A little reward. Why not?
&lt;/h3&gt;

&lt;p&gt;You can monetize your articles if you are a member of the Medium Partner Program. If your content engages readers and offers them value, you will probably receive the deserving reward.&lt;/p&gt;

&lt;h3&gt;
  
  
  A strong point in your profile
&lt;/h3&gt;

&lt;p&gt;Your articles will give recruiters an additional perspective on your abilities. It is more HR-friendly than the list of technologies we usually include on CVs. In my opinion, a public fingerprint is a strong point in the profile when competing with other candidates.&lt;/p&gt;

&lt;h3&gt;
  
  
  The productive loop
&lt;/h3&gt;

&lt;p&gt;Finally, we must recognize the positive energy generated when content is published and appreciated by readers. From my experience, the moment I felt most motivated was immediately after I posted one. That energy gives us more motivation to start new research! The loop returns to the beginning point.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6i529yc0vzax6xkaa9rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6i529yc0vzax6xkaa9rk.png" alt="The productive loop" width="800" height="836"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Notice
&lt;/h2&gt;

&lt;p&gt;One thing to keep in mind when using the method. You should clearly define the goal of the side projects. &lt;strong&gt;If you want to learn something new, do not fall back on old ideas simply because your articles in the categories have a lot of views.&lt;/strong&gt; Publishing the result on Medium is a step in the process for me. I don’t let it take my attention away from the initial objective.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, I explain the simple method to finish my applications. For readers who face the same problem, I hope the article could give you ideas to complete your side projects. Thank you for reading!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;More content at &lt;a href="https://plainenglish.io/" rel="noopener noreferrer"&gt;**PlainEnglish.io&lt;/a&gt;&lt;/em&gt;&lt;em&gt;. Sign up for our &lt;a href="http://newsletter.plainenglish.io/" rel="noopener noreferrer"&gt;**free weekly newsletter&lt;/a&gt;&lt;/em&gt;&lt;em&gt;. Follow us on &lt;a href="https://twitter.com/inPlainEngHQ" rel="noopener noreferrer"&gt;**Twitter&lt;/a&gt;&lt;/em&gt;&lt;strong&gt;, &lt;a href="https://www.linkedin.com/company/inplainenglish/" rel="noopener noreferrer"&gt;***LinkedIn&lt;/a&gt;&lt;/strong&gt;, &lt;a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw" rel="noopener noreferrer"&gt;**YouTube&lt;/a&gt;&lt;strong&gt;, and &lt;a href="https://discord.gg/GtDtUAvyhW" rel="noopener noreferrer"&gt;**Discord&lt;/a&gt;.&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**Interested in scaling your software startup&lt;/em&gt;&lt;em&gt;? Check out &lt;a href="https://circuit.ooo?utm=publication-post-cta" rel="noopener noreferrer"&gt;**Circuit&lt;/a&gt;&lt;/em&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
    <item>
      <title>4 daily use-cases of first-class functions in JavaScript</title>
      <dc:creator>Khoa DINH</dc:creator>
      <pubDate>Wed, 22 Dec 2021 07:10:35 +0000</pubDate>
      <link>https://dev.to/ddkhoa_blogging/4-daily-use-cases-of-first-class-functions-in-javascript-45c7</link>
      <guid>https://dev.to/ddkhoa_blogging/4-daily-use-cases-of-first-class-functions-in-javascript-45c7</guid>
      <description>&lt;p&gt;Every language has features that make it special. In this article, I want to mention the “first-class function” characteristic in JavaScript. The article isn’t a tutorial about how to use it. Instead, I would like to point out some real-life usages of the feature and the benefits it brings to developers. Let’s start!&lt;/p&gt;

&lt;h4&gt;
  
  
  What is “first-class function” about?
&lt;/h4&gt;

&lt;p&gt;The definition from &lt;a href="https://en.wikipedia.org/wiki/First-class_function" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In computer science, a programming language is said to have&lt;/em&gt; &lt;strong&gt;&lt;em&gt;first-class functions&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For example, in JavaScript, we can assign a function to a variable.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The definition is a bit confusing if we are reading it for the first time. However, the fact is that we used it even without knowing about it.&lt;/p&gt;

&lt;h4&gt;
  
  
  AddEventListener — The first lesson when learning JavaScript
&lt;/h4&gt;

&lt;p&gt;Back in the past, JavaScript was introduced to add dynamic behaviors to a website. For instance, we want to change the text when the user clicks on the button. Here comes the very first line of code when someone learns JavaScript.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In line 9, we passed the function as an argument to the method addEventListener. The function is associated with the event “click” of the button. When the event is fired, the function will run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s be curious — Part 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To understand the role of the feature, let’s think about languages where it isn’t available. Adding dynamic behaviors is something &lt;strong&gt;common&lt;/strong&gt; in UI development, regardless of the programming language. &lt;em&gt;What if we cannot pass the function as an argument?&lt;/em&gt; I am looking forward to your response in the comment section.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sending HTTP requests — The common task in JavaScript
&lt;/h4&gt;

&lt;p&gt;I will take &lt;a href="https://github.com/axios/axios" rel="noopener noreferrer"&gt;Axios&lt;/a&gt; as an example. It is one of the most popular JavaScript libraries to send HTTP requests. In a project, we might need to add some common configurations. For example, to send the JWT to the server, we want to add the header Authorization to all requests. So, we need a function to grab the JWT somewhere and add it to the header. It could be done using interceptors.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Again, we pass 2 functions as arguments of the &lt;code&gt;use&lt;/code&gt; method. The first function sets the token in the request’s header. The second function runs if there is an error (we don’t define it here for simplicity). When Axios processes a request, it will run all interceptors one by one to transform the user’s config to the full configuration. Then it will send the request to the server.&lt;/p&gt;

&lt;p&gt;The way Axios processes interceptors is a nice illustration of first-class function in JavaScript.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In line 23, the fulfilled and rejected functions we pass in the &lt;code&gt;use&lt;/code&gt;method are added to the &lt;em&gt;requestInterceptorChain&lt;/em&gt;. We store functions in an array. Then Axios will run each of them. Inside the while loop, you can see functions are assigned to variables to be called.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cd9qlqprmhz6u4an7wc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cd9qlqprmhz6u4an7wc.png" alt="How Axios handles 1 request. Interceptors are functions that are stored in 2 arrays."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s be curious — Part 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sending HTTP requests is not limited to frontend development. When developing the backend part, we might need to send requests to an external server. Could you explain to our community how HTTP request configurations are processed in your preferred language?&lt;/p&gt;

&lt;h4&gt;
  
  
  Handling HTTP requests in Node.js
&lt;/h4&gt;

&lt;p&gt;With Node.js, we can develop the backend part using JavaScript. Backend development is about handling HTTP requests, that is: to receive them, parse them, find the correct answers, and respond to clients. &lt;a href="https://www.toptal.com/nodejs/nodejs-frameworks-comparison" rel="noopener noreferrer"&gt;One of the most used frameworks of Node.js is Express.js&lt;/a&gt;. This framework uses &lt;em&gt;middleware&lt;/em&gt; to do the tasks mentioned above. Here is the definition of middleware from &lt;a href="https://expressjs.com/en/guide/using-middleware.html" rel="noopener noreferrer"&gt;Express official page&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Middleware&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;functions are functions that have access to the request object (&lt;code&gt;req&lt;/code&gt;), the response object (&lt;code&gt;res&lt;/code&gt;), and the next middleware function in the application’s request-response cycle.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can see the example of middleware below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The middleware function is passed in the &lt;code&gt;use&lt;/code&gt; method. It, in turn, accepts another function &lt;code&gt;next&lt;/code&gt; as an argument. The &lt;code&gt;next&lt;/code&gt; function is called at the end to pass the control to the following middleware in the stack.&lt;/p&gt;

&lt;p&gt;Express is popular and widely used for its &lt;em&gt;simplicity&lt;/em&gt;. “&lt;a href="https://expressjs.com/en/guide/using-middleware.html" rel="noopener noreferrer"&gt;An Express application is essentially a series of middleware function calls.&lt;/a&gt;” Despite the trivial looks, Express’s middleware can help us do all tasks of a web server: logging the request, compressing the response, setting cookies, preventing XSS attacks … just to mention a few.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56dpkxm0k5mqwidpnz2x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56dpkxm0k5mqwidpnz2x.png" alt="Schema of a simple Express application."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s be curious, again!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How HTTP requests are processed in other backend frameworks? Can you compare it to Express middleware? What are the advantages/disadvantages of each method? You see, there are a lot of questions to study!&lt;/p&gt;

&lt;h4&gt;
  
  
  Last but not least — Callback hell in JavaScript
&lt;/h4&gt;

&lt;p&gt;As you know, JavaScript is single-threaded. But it provides an effective mechanism to deal with long-running tasks. Instead of waiting for the task to be finished, we can immediately start the next one, and define what we need to do when the former task has been accomplished. It’s where callback functions come from — to define what should be run after a long-running task.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Callback functions give us a powerful tool to deal with I/O bound applications. However, every good thing can go bad if it is abused. You can see the example below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Multiple callback functions and if/else statements make the code hard to understand. It can become unmaintainable in the future if we add more logic. Because of this problem, newer features are introduced. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;Promises&lt;/a&gt; appeared to help us write a cleaner program. &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await" rel="noopener noreferrer"&gt;Async/await&lt;/a&gt; keyword allows us to write asynchronous code that looks like synchronous code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Wrap up
&lt;/h4&gt;

&lt;p&gt;In the article, I showed you some real-life examples of using “first-class function” in JavaScript. We use this feature daily and take it for granted. Through the examples, I hope you can see some cool things that the peculiarity offers to us. I left many questions for you as well. Curiosity is one of the characteristics that help us grow up. I will be glad to see your answer in the comment section so that we can learn from each other. You can also share the article with developers in other languages to discuss. Thank you for reading!&lt;/p&gt;

&lt;h4&gt;
  
  
  Resources
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://en.wikipedia.org/wiki/First-class_function" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/First-class_function&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://github.com/axios/axios" rel="noopener noreferrer"&gt;https://github.com/axios/axios&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.toptal.com/nodejs/nodejs-frameworks-comparison" rel="noopener noreferrer"&gt;https://www.toptal.com/nodejs/nodejs-frameworks-comparison&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://expressjs.com" rel="noopener noreferrer"&gt;https://expressjs.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://nodejs.org/api/fs.html#fsreadfilepath-options-callback" rel="noopener noreferrer"&gt;https://nodejs.org/api/fs.html#fsreadfilepath-options-callback&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="http://callbackhell.com/" rel="noopener noreferrer"&gt;http://callbackhell.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How BASIC knowledge helps us solve a ~2 million views question</title>
      <dc:creator>Khoa DINH</dc:creator>
      <pubDate>Tue, 21 Dec 2021 23:37:21 +0000</pubDate>
      <link>https://dev.to/ddkhoa_blogging/how-basic-knowledge-helps-us-solve-a-2-million-views-question-24i1</link>
      <guid>https://dev.to/ddkhoa_blogging/how-basic-knowledge-helps-us-solve-a-2-million-views-question-24i1</guid>
      <description>&lt;p&gt;You can check out the question &lt;a href="https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error" rel="noopener noreferrer"&gt;here&lt;/a&gt;. It’s the problem with the SSH private key. The answer is at the end of the article, I have created links in the table of contents for you to navigate. However, to enjoy the “that makes sense” moment, I encourage you to walk through each part of the article.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of content&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Introduction&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Background knowledge - Encryption&lt;br&gt;
2.1 Definition&lt;br&gt;
2.2 Symmetric encryption&lt;br&gt;
2.3 Asymmetric encryption&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-life examples of using SSH&lt;br&gt;
3.1 Using SSH with Git hosting service&lt;br&gt;
3.2 SSH configuration files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Answer the question&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrap up&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;To manipulate the remote server, we need a method that allows us to connect to them from our computer. SSH is one of those methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1o5x2cjyhauz4ar2fmug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1o5x2cjyhauz4ar2fmug.png" alt="SSH protocol."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SSH is a method that helps us establish&lt;/em&gt; &lt;strong&gt;&lt;em&gt;a secure connection to a remote server.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This connection allows us to work directly with the server’s shell. From there we can do all the tasks like we are doing with our machine.&lt;/p&gt;

&lt;p&gt;In the next section, I would like to review some background knowledge before starting to talk about different use cases of this tool. This part will help us to understand the meaning of a config file or an error message. So that we can determine what we need to do even when copying someone’s magic commands from Google.&lt;/p&gt;

&lt;h3&gt;
  
  
  Background knowledge : Encryption
&lt;/h3&gt;

&lt;p&gt;In the previous section, we mentioned &lt;strong&gt;&lt;em&gt;security&lt;/em&gt;&lt;/strong&gt;. SSH allows you to establish a secure connection. To do that, SSH uses different encryption algorithms.&lt;/p&gt;

&lt;h4&gt;
  
  
  Definition
&lt;/h4&gt;

&lt;p&gt;You can find the classic full definition of &lt;strong&gt;&lt;em&gt;encryption&lt;/em&gt;&lt;/strong&gt; at this &lt;a href="https://en.wikipedia.org/wiki/Encryption" rel="noopener noreferrer"&gt;link&lt;/a&gt;. To keep it simple, I would like to use my version.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Encryption is expressing information in a form that cannot be understood unless we have the means to decode it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are 2 categories of encryption algorithms: &lt;strong&gt;&lt;em&gt;symmetric encryption&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;asymmetric encryption&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Symmetric encryption
&lt;/h4&gt;

&lt;p&gt;Symmetric encryption is a class of encryption algorithms in which the &lt;strong&gt;encryption and decryption phase share a single key&lt;/strong&gt; (decryption is the reverse process of encryption). This key is a secret between the two parties in the conversation.&lt;/p&gt;

&lt;p&gt;Symmetric encryption keeps the information exchanged confidentially. Only those with the key can decrypt the information.&lt;/p&gt;

&lt;h4&gt;
  
  
  Asymmetric encryption
&lt;/h4&gt;

&lt;p&gt;In contrast to symmetric encryption, asymmetric encryption algorithms &lt;strong&gt;use 2 different keys to encrypt and decrypt information.&lt;/strong&gt; Each person needs a key pair consisting of a public key and a private key. While the public key can be made public to everyone, the private key is private to each person and &lt;strong&gt;cannot be shared with anyone&lt;/strong&gt;. When information is encrypted with one of the keys in a key pair, only the other key &lt;strong&gt;in the same pair&lt;/strong&gt; can decrypt it.&lt;/p&gt;

&lt;p&gt;(Notice the difference between a &lt;em&gt;secret key&lt;/em&gt; and a &lt;em&gt;private key&lt;/em&gt;. The private key cannot be shared. The secret key in symmetric encryption can be shared between the two parties.)&lt;/p&gt;

&lt;p&gt;Asymmetric encryption also gives us the same security as symmetric encryption. If Alice encrypts the message with Bob’s public key, then only Bobs with his private key can decrypt the message.&lt;/p&gt;

&lt;p&gt;In addition, it provides two &lt;em&gt;extra&lt;/em&gt; possibilities that symmetric encryption does not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;Allow us to identify who sent the information. (*)&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;The person who sent the information cannot deny the action.&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the case when Alice encrypts the message with her private key. Bob uses Alice’s public key to decrypt. If the decryption is successful, it proves that the message can only be sent from Alice. At the same time, Alice cannot deny that she sent this message. Because if it was sent by someone else, Bob couldn’t use the public key of Alice to decrypt.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj3jjy3fkt05pqctcdbe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj3jjy3fkt05pqctcdbe.png" alt="Decrypt successfully."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7l681g7n75d68vff123f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7l681g7n75d68vff123f.png" alt="Decrypt failed."&gt;&lt;/a&gt;&lt;br&gt;
The characteristic (*) is an important foundation for SSH because it helps the server &lt;strong&gt;identify&lt;/strong&gt; who is connecting to the system. This allows the server to accept or reject the connection. Authentication using SSH does not require a password. Instead, each person will use his/her private key to connect to the server, and the server keeps track of the list of people who can connect (see authorized_keys in the next section). Comparing two authentication methods using password and using the private key, the latter is the winner because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Authentication with the private key &lt;strong&gt;tells us who accessed the system, and that person cannot deny the fact.&lt;/strong&gt; In the first method, anyone who knows the password can connect to the system.&lt;/li&gt;
&lt;li&gt;  By not using a password, authentication with a private key is &lt;strong&gt;more convenient&lt;/strong&gt;. Each person in a group can use their private key to log into the common system instead of sharing a password. &lt;a href="https://www.kratikal.com/blog/5-risks-of-password-sharing-at-work/" rel="noopener noreferrer"&gt;Password sharing in the workplace can expose the business to &lt;strong&gt;&lt;em&gt;risks&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;. Therefore, we should &lt;a href="https://www.keepersecurity.com/blog/2021/07/06/4-rules-for-safe-password-sharing-in-the-workplace/" rel="noopener noreferrer"&gt;avoid shared passwords whenever possible.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Private key authentication allows us to &lt;strong&gt;automate&lt;/strong&gt; commands because the server shell does not prompt for the password.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are also the powers of SSH, and that’s why more and more systems move to this method. Now, we will talk about using SSH in practice.&lt;/p&gt;
&lt;h3&gt;
  
  
  Real-life examples of using SSH
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Using SSH with Git hosting service
&lt;/h4&gt;

&lt;p&gt;When working with Git hosting services like GitHub or GitLab, we can clone, push, pull a repository using HTTPS or SSH protocol.&lt;/p&gt;

&lt;p&gt;If we use HTTPS, every time we push, pull … We need to enter the username and password.&lt;br&gt;&lt;br&gt;
If we use SSH, we need to give GitHub/GitLab our public key. Then, every time we push, pull, instead of having to enter the username and password, we just need to enter the password of the private key (passphrase). If we don’t use the passphrase, then we don’t need to type anything! GitHub uses the public key to verify who we are and check if we have permission to read/write the repository.&lt;/p&gt;

&lt;p&gt;The second way is more convenient because we don’t have to manually type the username and passwords each time. If no passphrase is configured for the key, the push/pull command can be done by running a script. This allows us to automate the integration and deployment phase.&lt;/p&gt;
&lt;h4&gt;
  
  
  SSH configuration files
&lt;/h4&gt;

&lt;p&gt;To configure SSH, we will work with the .ssh directory under the home directory. This is the directory where the important files to use the SSH protocol locate. They are &lt;strong&gt;authorized_keys, known_hosts, and config&lt;/strong&gt;. Below, I would like to explain the meaning of each file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;authorized_keys&lt;/strong&gt;: This file contains a list of public keys that are allowed to access the system. When someone connects to the server, the message (encrypted with their private key) is decrypted by the public keys in this file. If the decryption is successful, the person is identified and is allowed to connect to the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, if you want to access the servers using the SSH protocol, you just need to add your public key to this file. The same principle applied when AWS gives us a .ppk file to access the container.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;known_hosts&lt;/strong&gt;: This file contains a list of public keys of remote servers that you have visited before. The information in the file helps the computer check the identity of the destination to make sure it is connecting to the right place, to avoid being redirected to a machine of a bad guy.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;config&lt;/strong&gt;: This file contains SSH settings. When we use frequently one particular SSH connection, we can save the parameters of that connection to this file. Then, the SSH command can be shortened.
For example, when you save the following text in the file ~/.ssh/config
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host alias  
   HostName hostname  
   User username  
   IdentityFile ~/.ssh/private_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then these 2 commands below will give the same result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh alias
ssh username@hostname -i ~/.ssh/private_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use this config file to set up a second GitLab account. You can see the tutorial &lt;a href="https://medium.com/uncaught-exception/setting-up-multiple-gitlab-accounts-82b70e88c437" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer the question
&lt;/h3&gt;

&lt;p&gt;Let’s go back to the question at the beginning. When the private key is not secured, you will see a message like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3wuncfzjti1cbogkkve.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3wuncfzjti1cbogkkve.png" alt="The private key is not protected as it should."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a common mistake when the private key is not protected as it should. In the theory section, we said that the private key is private to each person and is not shared with anyone. In this case, the key has a permission of 644, which means that the contents of the key can be read by anyone. That violates the principle of the private key and leads to the error.&lt;/p&gt;

&lt;p&gt;The problem is clear, we need to limit the permission of the file. We can use the permission of read-only or read-write by the owner. And the magic command is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chmod 400 ~/.ssh/[[PRIVATE KEY]]&lt;/code&gt;or &lt;code&gt;chmod 600 ~/.ssh/[[PRIVATE KEY]]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Done!&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrap up
&lt;/h3&gt;

&lt;p&gt;SSH is a protocol that we use daily at work. At first, I blindly copied and pasted the commands I found from Stack Overflow and hope it will work. But I did not understand why. When I had to configure more complex cases or recently worked with GitLab CI/CD, I was very confused. After revising the basics, I better understand SSH now. Through this post, I hope we can see the close relationship between basic knowledge and practical usage and feel more confident when dealing with issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://en.wikipedia.org/wiki/Encryption" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Encryption&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.kratikal.com/blog/5-risks-of-password-sharing-at-work/" rel="noopener noreferrer"&gt;https://www.kratikal.com/blog/5-risks-of-password-sharing-at-work/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.keepersecurity.com/blog/2021/07/06/4-rules-for-safe-password-sharing-in-the-workplace/" rel="noopener noreferrer"&gt;https://www.keepersecurity.com/blog/2021/07/06/4-rules-for-safe-password-sharing-in-the-workplace/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://medium.com/uncaught-exception/setting-up-multiple-gitlab-accounts-82b70e88c437" rel="noopener noreferrer"&gt;https://medium.com/uncaught-exception/setting-up-multiple-gitlab-accounts-82b70e88c437&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —&lt;/p&gt;

&lt;p&gt;I look forward to connecting with other people to learn from your perspectives. If you’ve ever had those “That makes sense!” moments, you can also share them in the comment section. That will help us learn from each other. Thank you for reading!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>security</category>
      <category>problemsolving</category>
      <category>ssh</category>
    </item>
  </channel>
</rss>
