<?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: Vatsal Mistry</title>
    <description>The latest articles on DEV Community by Vatsal Mistry (@mistryvatsal).</description>
    <link>https://dev.to/mistryvatsal</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%2F158052%2Fbeab77c5-6039-4b53-ae4b-eaa5133adca9.jpeg</url>
      <title>DEV Community: Vatsal Mistry</title>
      <link>https://dev.to/mistryvatsal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mistryvatsal"/>
    <language>en</language>
    <item>
      <title>Microblog - Create a new non-root user with sudo privileges on Ubuntu based DigitalOcean Droplet configured with SSH</title>
      <dc:creator>Vatsal Mistry</dc:creator>
      <pubDate>Sat, 30 May 2020 18:44:22 +0000</pubDate>
      <link>https://dev.to/mistryvatsal/microblog-create-a-new-non-root-user-with-sudo-privileges-on-ubuntu-based-digitalocean-droplet-configured-with-ssh-1l3</link>
      <guid>https://dev.to/mistryvatsal/microblog-create-a-new-non-root-user-with-sudo-privileges-on-ubuntu-based-digitalocean-droplet-configured-with-ssh-1l3</guid>
      <description>&lt;p&gt;This post will walk you through steps of creating a new non root user and configure sudo privileges with it. This post not just focuses on DigitalOcean Droplet but rather can be used for any linux based system.&lt;/p&gt;

&lt;p&gt;Well, so you've spin up your Digital Ocean droplet and configured it with your SSH and have a root user to login from your terminal or bash.&lt;/p&gt;

&lt;p&gt;But it is not a good option to use the root user, as the root user has the maximum level of access and rights, which might accidentally cause some problem. So a better choice is to create a new user.&lt;/p&gt;

&lt;p&gt;Let's follow through the steps to create a new user and assign sudo privileges to it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Login to your droplet using terminal or bash or PuTTY(Windows).&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh root@&amp;lt;ip-address-of-your-droplet&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a new user, &lt;code&gt;&amp;lt;new-user&amp;gt;&lt;/code&gt; (Replace &lt;code&gt;&amp;lt;new-user&amp;gt;&lt;/code&gt; with your desired username).&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adduser &amp;lt;new-user&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Congratulations, 😃 . You've created a new user. You can verify it using,&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &amp;lt;new-user&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Let us add the &lt;code&gt;&amp;lt;new-user&amp;gt;&lt;/code&gt; to the sudo group to get the sudo privileges.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; &lt;span class="nb"&gt;sudo&lt;/span&gt; &amp;lt;new-user&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now let us add SSH key for the new user so that next time we can connect to droplet using &lt;code&gt;&amp;lt;new-user&amp;gt;&lt;/code&gt; using SSH. Switch the user from root to  using,&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;su - &amp;lt;new-user&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a directory .ssh into home dir. Change permissions for that dir. Follow the commands,&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; ~/.ssh
&lt;span class="nb"&gt;sudo chmod &lt;/span&gt;700 ~/.ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a file named authorized_keys and paste your SSH key in there. Also change the permission for it.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vim ~/.ssh/authorized_keys
Paste the key and save the file.
&lt;span class="nb"&gt;sudo chmod &lt;/span&gt;600 ~/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;Note&lt;/code&gt;: If you want to know how to generate SSH keys follow this doc from Git &lt;a href="https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Congratulations, 😃 . You've successfully created a non-root &lt;code&gt;&amp;lt;new-user&amp;gt;&lt;/code&gt; with sudo privileges to work with. You can now login your droplet using,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```bash
ssh &amp;lt;new-user&amp;gt;@&amp;lt;ip-address-of-your-droplet&amp;gt;
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thanks for reading through.&lt;br&gt;
Comment down if you have any doubts.&lt;br&gt;
Like if you find this post useful. I welcome your opinions and constructive criticism. You can find me on &lt;a href="https://twitter.com/mistryvatsal11"&gt;twitter&lt;/a&gt; or my &lt;a href="https://mistryvatsal.github.io"&gt;website&lt;/a&gt;.&lt;br&gt;
Cheers!&lt;/p&gt;

</description>
      <category>digitalocean</category>
      <category>linux</category>
      <category>ubuntu</category>
      <category>serverconfiguration</category>
    </item>
    <item>
      <title>How easy type conversion in Python helped me! A solution to problem from Code Jam 2019.</title>
      <dc:creator>Vatsal Mistry</dc:creator>
      <pubDate>Thu, 18 Apr 2019 19:03:49 +0000</pubDate>
      <link>https://dev.to/mistryvatsal/how-easy-type-conversion-in-python-helped-me-a-solution-to-problem-from-code-jam-2019-573d</link>
      <guid>https://dev.to/mistryvatsal/how-easy-type-conversion-in-python-helped-me-a-solution-to-problem-from-code-jam-2019-573d</guid>
      <description>&lt;p&gt;&lt;strong&gt;Foregone Solution&lt;/strong&gt; — A problem from &lt;a href="https://codingcompetitions.withgoogle.com/codejam" rel="noopener noreferrer"&gt;Google Code Jam&lt;/a&gt;'s Qualifier Round this year felt like so easy to code.&lt;/p&gt;

&lt;p&gt;You can checkout the full problem description at this &lt;a href="https://codingcompetitions.withgoogle.com/codejam/round/0000000000051705/0000000000088231" rel="noopener noreferrer"&gt;LINK&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem(Source : Google Code Jam 2019 Website)
&lt;/h2&gt;

&lt;p&gt;Someone just won the Code Jam lottery, and we owe them N jamcoins! However, when we tried to print out an over sized check, we encountered a problem. The value of N, which is an integer, includes at least one digit that is a 4... and the 4 key on the keyboard of our over sized check printer is broken.&lt;/p&gt;

&lt;p&gt;Fortunately, we have a workaround: we will send our winner two checks for positive integer amounts A and B, such that neither A nor B contains any digit that is a 4, and A + B = N. Please help us find any pair of values A and B that satisfy these conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;While reading out the problem description, I read the input constraints and range which were around 10¹⁰⁰. So it was a bad idea to think of a very straight loop-based solution, that would strike the time complexity showing the nightmarish message “ &lt;em&gt;Time limit Exceeded !&lt;/em&gt; ”.&lt;/p&gt;

&lt;p&gt;So I thought of dealing this with the help of strings. Python saved me!&lt;/p&gt;

&lt;p&gt;Assuming you’ve read the problem description through the link above, there is a number N which may contain the digit 4 with any number of occurrences. The task was to find out two numbers A and B such that A and B doesn’t contain any occurrence of the digit 4 and summation of A and B should equal N(A+B=N).&lt;/p&gt;

&lt;p&gt;So I thought of creating a new number let’s assume A for now, that would be same in length as N(&lt;em&gt;length means number of digits in the number&lt;/em&gt;). The idea is while constructing the number A, we would analyze the number N digit by digit. For each occurrence of digit 4 in number N, we would add digit 1 in the number A. For rest of the digits in N, add digit 0 in the A. Following this, I got a number A.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3gzh3tt283ize174wdb6.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3gzh3tt283ize174wdb6.jpg" alt="Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I obtained the other number B by subtracting newly constructed A from N. And you see, I got two numbers A and B that do not contain digit 4 and the summation is equal to N.&lt;/p&gt;

&lt;p&gt;For implementing this logic, I could not think of anything, but Python. The easy type conversions from integer to string or string to list and viz made it so easy to achieve this working.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Code.&lt;/p&gt;


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


&lt;h2&gt;
  
  
  My View
&lt;/h2&gt;

&lt;p&gt;This way it cracked all the test cases, no matter how large the input number was!&lt;/p&gt;

&lt;p&gt;I believe the same logic can be implemented in various other languages, possibly the best in terms of time would be in C/C++, but Python just makes it super easy. You can switch from different data types with just few keywords and as you want.&lt;/p&gt;

&lt;p&gt;I encourage any reader to try out this in some other language or in Python with less lines of code.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;" The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code — not in reams of trivial code that bores the reader to death. "&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;-- Guido Van Rossum&lt;/em&gt; &lt;/p&gt;


&lt;div class="ltag__tag ltag__tag__id__25"&gt;
    &lt;div class="ltag__tag__content"&gt;
      &lt;h2&gt;#&lt;a href="https://dev.to/t/python" class="ltag__tag__link"&gt;python&lt;/a&gt; Follow
&lt;/h2&gt;
      &lt;div class="ltag__tag__summary"&gt;
        import antigravity
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__tag ltag__tag__id__6043"&gt;
    &lt;div class="ltag__tag__content"&gt;
      &lt;h2&gt;#&lt;a href="https://dev.to/t/pythonprogramming" class="ltag__tag__link"&gt;pythonprogramming&lt;/a&gt; Follow
&lt;/h2&gt;
      &lt;div class="ltag__tag__summary"&gt;
        
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__tag ltag__tag__id__12511"&gt;
    &lt;div class="ltag__tag__content"&gt;
      &lt;h2&gt;#&lt;a href="https://dev.to/t/codejam" class="ltag__tag__link"&gt;codejam&lt;/a&gt; Follow
&lt;/h2&gt;
      &lt;div class="ltag__tag__summary"&gt;
        
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__tag ltag__tag__id__266"&gt;
    &lt;div class="ltag__tag__content"&gt;
      &lt;h2&gt;#&lt;a href="https://dev.to/t/firstpost" class="ltag__tag__link"&gt;firstpost&lt;/a&gt; Follow
&lt;/h2&gt;
      &lt;div class="ltag__tag__summary"&gt;
        
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Thanks for reading through. I welcome feedback and constructive criticism. I can be reached on Twitter &lt;a href="https://twitter.com/mistryvatsal11" rel="noopener noreferrer"&gt;@mistryvatsal11&lt;/a&gt; or through my personal website &lt;a href="https://mistryvatsal.github.io" rel="noopener noreferrer"&gt;mistryvatsal.github.io&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>google</category>
      <category>codejam</category>
    </item>
  </channel>
</rss>
