<?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: Yeasin's </title>
    <description>The latest articles on DEV Community by Yeasin's  (@yeasin4745).</description>
    <link>https://dev.to/yeasin4745</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3237863%2F08ec2a57-9ad3-4bcc-88c6-aef9b3f41a49.png</url>
      <title>DEV Community: Yeasin's </title>
      <link>https://dev.to/yeasin4745</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yeasin4745"/>
    <language>en</language>
    <item>
      <title>File and Directory Management in Linux</title>
      <dc:creator>Yeasin's </dc:creator>
      <pubDate>Sun, 25 Oct 2026 02:25:11 +0000</pubDate>
      <link>https://dev.to/yeasin4745/file-and-directory-management-in-linux-jj8</link>
      <guid>https://dev.to/yeasin4745/file-and-directory-management-in-linux-jj8</guid>
      <description>&lt;p&gt;Everything in &lt;b&gt;Linux&lt;/b&gt; is a file. Your documents are files, your programs are files, your terminal is a file, even your hardware devices are represented as files. This single idea is what makes Linux so powerful and consistent — but it also means that if you want to be productive on the command line, you must learn to manage files and directories fluently.&lt;/p&gt;

&lt;p&gt;In this guide, we'll cover the essential commands and concepts: navigating the filesystem, creating, copying, moving, and deleting files, understanding the directory structure, finding files fast, and — critically — how to avoid the mistakes that destroy data.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Linux Directory Structure: Start Here
&lt;/h2&gt;

&lt;p&gt;Before touching any command, you need a map. Unlike Windows with its &lt;code&gt;C:\&lt;/code&gt; drive, Linux has &lt;strong&gt;one single tree&lt;/strong&gt; that starts at the root directory, written as &lt;code&gt;/&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bin   dev  home  lib32  media  opt   root  sbin  srv  tmp  var
boot  etc  lib   lib64  mnt    proc  run   snap  sys  usr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important ones to know:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory&lt;/th&gt;
&lt;th&gt;What lives here&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/home&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Personal folders of normal users (&lt;code&gt;/home/yeasin&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/root&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Home directory of the root user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;System-wide configuration files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/var&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Variable data: logs (&lt;code&gt;/var/log&lt;/code&gt;), caches, websites&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/tmp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Temporary files — often cleared on reboot&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/usr&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Installed programs and their files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/opt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Third-party / manually installed software&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/dev&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Device files (disks, terminals appear here)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/proc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Virtual files exposing kernel and process info&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Unlike Windows, Linux uses &lt;code&gt;/&lt;/code&gt; (forward slash) as the separator, and paths are case-sensitive. &lt;code&gt;/home/Yeasin&lt;/code&gt; and &lt;code&gt;/home/yeasin&lt;/code&gt; are two different paths.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Absolute vs relative paths
&lt;/h3&gt;

&lt;p&gt;There are two ways to write a path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Absolute path&lt;/strong&gt; — starts from &lt;code&gt;/&lt;/code&gt;: &lt;code&gt;/home/yeasin/projects/app.js&lt;/code&gt; (works from anywhere)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relative path&lt;/strong&gt; — starts from your current location: &lt;code&gt;projects/app.js&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two special names help you move around:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; — the current directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;..&lt;/code&gt; — the parent directory (one level up)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So &lt;code&gt;cd ..&lt;/code&gt; moves up, and &lt;code&gt;cd ../..&lt;/code&gt; moves up two levels.&lt;/p&gt;




&lt;h2&gt;
  
  
  Navigating: pwd, ls, and cd
&lt;/h2&gt;

&lt;p&gt;Always know where you are before you act. Three commands handle all navigation:&lt;/p&gt;

&lt;h3&gt;
  
  
  Where am I? — &lt;code&gt;pwd&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pwd&lt;/code&gt; (print working directory) shows your current location in the tree. It sounds trivial, but in long terminal sessions with multiple tabs, it saves you from running commands in the wrong place.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's here? — &lt;code&gt;ls&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;            &lt;span class="c"&gt;# list names only&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;         &lt;span class="c"&gt;# long format: permissions, owner, size, date&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;         &lt;span class="c"&gt;# include hidden files (starting with .)&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-la&lt;/span&gt;        &lt;span class="c"&gt;# long + hidden, the everyday combo&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lh&lt;/span&gt;        &lt;span class="c"&gt;# long + human-readable sizes (K, M, G)&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt;        &lt;span class="c"&gt;# sorted by modification time, newest first&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;total 24K
drwxr-xr-x 3 yeasin yeasin 4.0K Oct 17 12:00 projects
-rw-r--r-- 1 yeasin yeasin 2.2K Oct 16 18:42 notes.txt
drwxr-xr-x 2 yeasin yeasin 4.0K Oct 15 09:10 .ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two useful extras: &lt;code&gt;ls -R&lt;/code&gt; lists directories recursively, and &lt;code&gt;ls /etc&lt;/code&gt; lists a directory without entering it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Moving around — &lt;code&gt;cd&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /var/log        &lt;span class="c"&gt;# go to an absolute path&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;projects        &lt;span class="c"&gt;# go into a subdirectory (relative)&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ..              &lt;span class="c"&gt;# go up one level&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~               &lt;span class="c"&gt;# go to your home directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; -               &lt;span class="c"&gt;# go back to the previous directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt;                 &lt;span class="c"&gt;# no argument = home directory too&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;cd -&lt;/code&gt; is a small trick worth remembering: it toggles between your last two locations, like a channel-swap button.&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating Files and Directories
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Touch — create an empty file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;notes.txt
&lt;span class="nb"&gt;touch &lt;/span&gt;a.txt b.txt c.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;touch&lt;/code&gt; also has a second job: it updates the timestamp of an existing file without changing its content.&lt;/p&gt;

&lt;h3&gt;
  
  
  mkdir — create directories
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;projects
&lt;span class="nb"&gt;mkdir &lt;/span&gt;projects/src projects/docs    &lt;span class="c"&gt;# multiple at once&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; projects/src/components    &lt;span class="c"&gt;# create parents as needed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-p&lt;/code&gt; flag is the one to remember. Without it, creating &lt;code&gt;projects/src/components&lt;/code&gt; fails if &lt;code&gt;projects&lt;/code&gt; doesn't exist yet. With &lt;code&gt;-p&lt;/code&gt;, the whole chain is created in one shot.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating files with content
&lt;/h3&gt;

&lt;p&gt;For a quick file with text, you don't even need an editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello, world"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; hello.txt      &lt;span class="c"&gt;# overwrite&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Second line"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; hello.txt      &lt;span class="c"&gt;# append&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Copying and Moving
&lt;/h2&gt;

&lt;h3&gt;
  
  
  cp — copy
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp &lt;/span&gt;notes.txt backup.txt             &lt;span class="c"&gt;# copy a file&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; projects projects-backup      &lt;span class="c"&gt;# copy a directory (recursive required)&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; notes.txt old.txt            &lt;span class="c"&gt;# ask before overwriting&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.txt /tmp/                      &lt;span class="c"&gt;# copy all .txt files somewhere&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; &lt;code&gt;cp&lt;/code&gt; overwrites existing files silently by default. If &lt;code&gt;old.txt&lt;/code&gt; already exists, it's gone with no confirmation. Use &lt;code&gt;-i&lt;/code&gt; (interactive) whenever you're unsure. A safer habit for a session: &lt;code&gt;alias cp='cp -i'&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that &lt;code&gt;cp&lt;/code&gt; for a directory &lt;strong&gt;requires&lt;/strong&gt; &lt;code&gt;-r&lt;/code&gt; — without it, cp refuses to copy directories. This is a safety feature, not a limitation.&lt;/p&gt;

&lt;h3&gt;
  
  
  mv — move and rename
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;mv&lt;/code&gt; is two commands in one — it moves files and it renames them (renaming &lt;em&gt;is&lt;/em&gt; moving to a new name):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mv &lt;/span&gt;notes.txt documents/        &lt;span class="c"&gt;# move into a directory&lt;/span&gt;
&lt;span class="nb"&gt;mv &lt;/span&gt;notes.txt todo.txt          &lt;span class="c"&gt;# rename&lt;/span&gt;
&lt;span class="nb"&gt;mv&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; old.txt documents/      &lt;span class="c"&gt;# ask before overwriting&lt;/span&gt;
&lt;span class="nb"&gt;mv &lt;/span&gt;projects/ archive/         &lt;span class="c"&gt;# move a whole directory&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;mv&lt;/code&gt; is fast even for huge files, because moving on the same filesystem doesn't copy data — it just updates the pointer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Deleting: rm, rmdir, and Staying Safe
&lt;/h2&gt;

&lt;p&gt;This is the part where mistakes hurt, so let's be careful and precise.&lt;/p&gt;

&lt;h3&gt;
  
  
  rm — delete files
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm &lt;/span&gt;notes.txt          &lt;span class="c"&gt;# delete one file — no recycle bin, no undo&lt;/span&gt;
&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; notes.txt       &lt;span class="c"&gt;# ask for confirmation first&lt;/span&gt;
&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; projects        &lt;span class="c"&gt;# delete a directory and everything inside&lt;/span&gt;
&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; stuck.txt      &lt;span class="c"&gt;# force: ignore warnings, don't ask&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three facts every Linux user must internalize:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;There is no trash bin.&lt;/strong&gt; &lt;code&gt;rm&lt;/code&gt; is permanent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;rm -r&lt;/code&gt; is powerful enough to delete an entire system.&lt;/strong&gt; That's why &lt;code&gt;sudo rm -rf /&lt;/code&gt; is the most infamous command in Linux — it means "delete everything, don't ask, no exceptions."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;rm&lt;/code&gt; doesn't ask for confirmation by default.&lt;/strong&gt; A typo in a path can delete the wrong thing instantly.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  rmdir — the cautious alternative
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rmdir &lt;/span&gt;empty-folder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;rmdir&lt;/code&gt; only removes &lt;strong&gt;empty&lt;/strong&gt; directories. If there's anything inside, it refuses. This makes it a great "safe" option when you expect a folder to be empty and want to be alerted if it's not.&lt;/p&gt;

&lt;h3&gt;
  
  
  Safer deletion patterns
&lt;/h3&gt;

&lt;p&gt;A professional habit: &lt;strong&gt;list first, then delete.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls &lt;/span&gt;projects/&lt;span class="k"&gt;*&lt;/span&gt;.log    &lt;span class="c"&gt;# see exactly what will be deleted&lt;/span&gt;
&lt;span class="nb"&gt;rm &lt;/span&gt;projects/&lt;span class="k"&gt;*&lt;/span&gt;.log    &lt;span class="c"&gt;# now delete it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even better — use &lt;code&gt;-i&lt;/code&gt; once and build the habit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-ri&lt;/span&gt; old-projects/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; One character in the wrong place makes &lt;code&gt;rm&lt;/code&gt; dangerous. &lt;code&gt;rm -rf projects /&lt;/code&gt; (with a space before the slash) would delete &lt;code&gt;projects&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; the root filesystem. This is not a joke command — it's a real typo people have made. Always read the full command once before pressing Enter, especially with &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Viewing Files
&lt;/h2&gt;

&lt;p&gt;Before editing, you usually want to look inside a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;notes.txt        &lt;span class="c"&gt;# print the whole file&lt;/span&gt;
less notes.txt      &lt;span class="c"&gt;# open in a pager: q to quit, / to search&lt;/span&gt;
&lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 20 notes.txt  &lt;span class="c"&gt;# first 20 lines&lt;/span&gt;
&lt;span class="nb"&gt;tail&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 20 notes.txt  &lt;span class="c"&gt;# last 20 lines&lt;/span&gt;
&lt;span class="nb"&gt;tail&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; app.log      &lt;span class="c"&gt;# follow a log file live as it grows&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The distinction matters for real work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cat&lt;/code&gt; is fine for small files, but a 10,000-line log will flood your terminal.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;less&lt;/code&gt; lets you scroll, search (&lt;code&gt;/pattern&lt;/code&gt;), and quit with &lt;code&gt;q&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tail -f&lt;/code&gt; is how sysadmins watch logs in real time — every new line appears as it's written. Debugging a live service? This is your window.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Finding Files: find and locate
&lt;/h2&gt;

&lt;h3&gt;
  
  
  find — powerful, real-time search
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find /var/log &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.log"&lt;/span&gt;             &lt;span class="c"&gt;# by name&lt;/span&gt;
find ~ &lt;span class="nt"&gt;-type&lt;/span&gt; d &lt;span class="nt"&gt;-name&lt;/span&gt; projects            &lt;span class="c"&gt;# directories only&lt;/span&gt;
find /etc &lt;span class="nt"&gt;-iname&lt;/span&gt; &lt;span class="s2"&gt;"*.conf"&lt;/span&gt;                &lt;span class="c"&gt;# case-insensitive&lt;/span&gt;
find &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-size&lt;/span&gt; +100M                       &lt;span class="c"&gt;# files bigger than 100 MB&lt;/span&gt;
find &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-mtime&lt;/span&gt; &lt;span class="nt"&gt;-7&lt;/span&gt;                        &lt;span class="c"&gt;# modified in the last 7 days&lt;/span&gt;
find &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.tmp"&lt;/span&gt; &lt;span class="nt"&gt;-delete&lt;/span&gt;             &lt;span class="c"&gt;# find AND delete in one command&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;find&lt;/code&gt; walks the actual filesystem, so it's always accurate — but can be slow on huge trees. The &lt;code&gt;-delete&lt;/code&gt; action at the end is efficient, but treat it like &lt;code&gt;rm&lt;/code&gt;: run the command &lt;strong&gt;without&lt;/strong&gt; &lt;code&gt;-delete&lt;/code&gt; first to preview the results.&lt;/p&gt;

&lt;h3&gt;
  
  
  locate — fast, database-based
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;plocate &lt;span class="nt"&gt;-y&lt;/span&gt;
locate nginx.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;locate&lt;/code&gt; answers instantly because it searches a pre-built database (updated daily, or manually with &lt;code&gt;sudo updatedb&lt;/code&gt;). The tradeoff: very new files may not be in the database yet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wildcards: The Pattern Language of the Shell
&lt;/h2&gt;

&lt;p&gt;Wildcards (glob patterns) are how you select many files at once — and they work with &lt;strong&gt;every&lt;/strong&gt; command:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Matches&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Any number of any characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;?&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exactly one character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[abc]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;One character: a, b, or c&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;All files ending in &lt;code&gt;.txt&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;file?.log&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;file1.log&lt;/code&gt;, &lt;code&gt;fileA.log&lt;/code&gt; — but not &lt;code&gt;file10.log&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Real examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.jpg /backup/
&lt;span class="nb"&gt;rm &lt;/span&gt;old-&lt;span class="k"&gt;*&lt;/span&gt;.tmp
&lt;span class="nb"&gt;mv &lt;/span&gt;report?.pdf reports/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The shell expands the wildcard &lt;strong&gt;before&lt;/strong&gt; the command runs — the command never sees the &lt;code&gt;*&lt;/code&gt;, only the expanded list. This is why listing with &lt;code&gt;ls&lt;/code&gt; first is a reliable preview of what a glob will touch.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  A Practical Workflow: Organizing a Messy Folder
&lt;/h2&gt;

&lt;p&gt;Let's combine everything into a realistic scenario. Your home directory is full of loose files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; ~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.js  index.html  notes.txt  package.json  old-report.pdf  server.js  styles.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clean it up in a few commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/web/&lt;span class="o"&gt;{&lt;/span&gt;src,docs,reports&lt;span class="o"&gt;}&lt;/span&gt;          &lt;span class="c"&gt;# create the structure in one line&lt;/span&gt;
&lt;span class="nb"&gt;mv&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.js &lt;span class="k"&gt;*&lt;/span&gt;.css &lt;span class="k"&gt;*&lt;/span&gt;.html ~/web/src/            &lt;span class="c"&gt;# move code files&lt;/span&gt;
&lt;span class="nb"&gt;mv &lt;/span&gt;notes.txt ~/web/docs/
&lt;span class="nb"&gt;mv &lt;/span&gt;old-report.pdf ~/web/reports/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find ~/web &lt;span class="nt"&gt;-type&lt;/span&gt; f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/yeasin/web/src/app.js
/home/yeasin/web/src/server.js
/home/yeasin/web/src/index.html
/home/yeasin/web/src/styles.css
/home/yeasin/web/docs/notes.txt
/home/yeasin/web/reports/old-report.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;{src,docs,reports}&lt;/code&gt; syntax is &lt;strong&gt;brace expansion&lt;/strong&gt; — another shell trick worth remembering. &lt;code&gt;mkdir -p a/{one,two,three}&lt;/code&gt; creates three subdirectories instantly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes and Troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. "No such file or directory" — but the file is right there&lt;/strong&gt;&lt;br&gt;
Linux paths are &lt;strong&gt;case-sensitive&lt;/strong&gt;: &lt;code&gt;Notes.txt&lt;/code&gt; is not &lt;code&gt;notes.txt&lt;/code&gt;. Use &lt;code&gt;ls&lt;/code&gt; and tab completion (press &lt;code&gt;Tab&lt;/code&gt; to auto-complete names) to avoid typos entirely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Deleted something you needed&lt;/strong&gt;&lt;br&gt;
No recycle bin exists, so recovery depends on backups. The lesson: build the list-first habit, and use &lt;code&gt;mv&lt;/code&gt; to a "trash" folder instead of &lt;code&gt;rm&lt;/code&gt; for anything you might miss:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/.trash
&lt;span class="nb"&gt;mv &lt;/span&gt;important.txt ~/.trash/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;cp&lt;/code&gt; says "omitting directory"&lt;/strong&gt;&lt;br&gt;
You forgot &lt;code&gt;-r&lt;/code&gt;. Directories always need &lt;code&gt;cp -r&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Running out of space — finding the culprit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;                     &lt;span class="c"&gt;# disk usage per filesystem&lt;/span&gt;
&lt;span class="nb"&gt;du&lt;/span&gt; &lt;span class="nt"&gt;-sh&lt;/span&gt; /var/&lt;span class="k"&gt;*&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;   &lt;span class="c"&gt;# which folders are big&lt;/span&gt;
find ~ &lt;span class="nt"&gt;-size&lt;/span&gt; +500M        &lt;span class="c"&gt;# huge files in your home&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Permission denied&lt;/strong&gt;&lt;br&gt;
Some files belong to other users or root. Don't reflexively add &lt;code&gt;sudo&lt;/code&gt; — first check who owns the file with &lt;code&gt;ls -l&lt;/code&gt;, and prefer fixing ownership or location rather than escalating. (&lt;code&gt;chown&lt;/code&gt; and &lt;code&gt;chmod&lt;/code&gt; deserve their own article — coming next in this series.)&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Linux has &lt;strong&gt;one filesystem tree&lt;/strong&gt; starting at &lt;code&gt;/&lt;/code&gt;, with a standard directory layout — learn &lt;code&gt;/home&lt;/code&gt;, &lt;code&gt;/etc&lt;/code&gt;, &lt;code&gt;/var&lt;/code&gt;, and &lt;code&gt;/tmp&lt;/code&gt; first.&lt;/li&gt;
&lt;li&gt;Navigation is three commands: &lt;strong&gt;&lt;code&gt;pwd&lt;/code&gt;&lt;/strong&gt; (where am I), &lt;strong&gt;&lt;code&gt;ls&lt;/code&gt;&lt;/strong&gt; (what's here), &lt;strong&gt;&lt;code&gt;cd&lt;/code&gt;&lt;/strong&gt; (go there).&lt;/li&gt;
&lt;li&gt;Create with &lt;strong&gt;&lt;code&gt;touch&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;mkdir -p&lt;/code&gt;&lt;/strong&gt;; copy with &lt;strong&gt;&lt;code&gt;cp -r&lt;/code&gt;&lt;/strong&gt;; move/rename with &lt;strong&gt;&lt;code&gt;mv&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;rm&lt;/code&gt; is permanent&lt;/strong&gt; — there is no trash bin. List first (&lt;code&gt;ls&lt;/code&gt;), then delete, and use &lt;code&gt;-i&lt;/code&gt; when unsure.&lt;/li&gt;
&lt;li&gt;View files with &lt;strong&gt;&lt;code&gt;less&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;head&lt;/code&gt;/&lt;code&gt;tail&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;tail -f&lt;/code&gt;&lt;/strong&gt; for live logs.&lt;/li&gt;
&lt;li&gt;Find files with &lt;strong&gt;&lt;code&gt;find&lt;/code&gt;&lt;/strong&gt; (accurate, real-time) or &lt;strong&gt;&lt;code&gt;locate&lt;/code&gt;&lt;/strong&gt; (instant, database-based).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wildcards&lt;/strong&gt; (&lt;code&gt;*&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;) work with every command and are expanded by the shell before the command runs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Master these commands until they're muscle memory, and the command line stops feeling like a struggle — it starts feeling like home. Every sysadmin skill you learn next, from servers to security, builds on this foundation.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>bash</category>
      <category>sysadmin</category>
      <category>devops</category>
    </item>
    <item>
      <title>SSH and Remote Access Configuration in Linux</title>
      <dc:creator>Yeasin's </dc:creator>
      <pubDate>Sat, 17 Oct 2026 15:01:44 +0000</pubDate>
      <link>https://dev.to/yeasin4745/ssh-and-remote-access-configuration-in-linux-1l85</link>
      <guid>https://dev.to/yeasin4745/ssh-and-remote-access-configuration-in-linux-1l85</guid>
      <description>&lt;p&gt;Almost every server in the world is managed remotely. Nobody walks into a data center, plugs in a monitor, and types commands. Instead, administrators connect over the network using &lt;strong&gt;SSH (Secure Shell)&lt;/strong&gt; — the standard, encrypted way to control one computer from another.&lt;/p&gt;

&lt;p&gt;If you are learning Linux system administration, this is one of the first real skills you need. In this guide, we will cover what SSH is, how it works under the hood, how to install and configure the SSH server on Debian and Ubuntu, how to set up passwordless login with keys, and — most importantly — how to lock down your server so it is safe on the public internet.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is SSH and Why Does It Matter?
&lt;/h2&gt;

&lt;p&gt;SSH is a protocol that gives you a &lt;strong&gt;secure, encrypted terminal&lt;/strong&gt; on a remote machine. When you connect to a server with SSH, it is as if you are sitting in front of it with a keyboard — except you could be on the other side of the world.&lt;/p&gt;

&lt;p&gt;Before SSH, people used tools like &lt;code&gt;telnet&lt;/code&gt;, which sent everything — including your password — in plain text. Anyone watching the network traffic could read it. SSH was created to fix exactly this problem.&lt;/p&gt;

&lt;p&gt;With SSH, everything is encrypted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your password and commands&lt;/li&gt;
&lt;li&gt;The files you transfer&lt;/li&gt;
&lt;li&gt;The entire session traffic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SSH is used for far more than terminals, though. Once you know it, you will use it for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Administering remote servers (your daily driver)&lt;/li&gt;
&lt;li&gt;Securely copying files (&lt;code&gt;scp&lt;/code&gt;, &lt;code&gt;rsync&lt;/code&gt;, &lt;code&gt;sftp&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Tunneling other traffic through an encrypted channel (port forwarding)&lt;/li&gt;
&lt;li&gt;Git operations with remote repositories&lt;/li&gt;
&lt;li&gt;Automated deployments from CI/CD pipelines&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How SSH Works: The Basic Flow
&lt;/h2&gt;

&lt;p&gt;Before the commands, it helps to understand the mechanics. An SSH connection always has two sides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSH client&lt;/strong&gt; — the machine you are sitting at (your laptop, or even Termux on a phone)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSH server (sshd)&lt;/strong&gt; — the remote machine you want to log into&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The flow looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You run &lt;code&gt;ssh user@server-ip&lt;/code&gt; on the client.&lt;/li&gt;
&lt;li&gt;The client and server perform a &lt;strong&gt;key exchange&lt;/strong&gt; and agree on encryption keys for this session.&lt;/li&gt;
&lt;li&gt;The server proves its identity using its &lt;strong&gt;host key&lt;/strong&gt; (stored in &lt;code&gt;/etc/ssh/&lt;/code&gt; on the server).&lt;/li&gt;
&lt;li&gt;The client verifies your identity — with a &lt;strong&gt;password&lt;/strong&gt; or, better, a &lt;strong&gt;public/private key pair&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;An encrypted session opens, and you get a shell on the remote machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The first time you connect to any server, SSH asks you to confirm the server's fingerprint. It then saves it to &lt;code&gt;~/.ssh/known_hosts&lt;/code&gt;. From then on, if that fingerprint ever changes, SSH refuses to connect and warns you loudly — that is protection against man-in-the-middle attacks, not a bug.&lt;/p&gt;
&lt;/blockquote&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxdaoxsixykqs0ncr7eng.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxdaoxsixykqs0ncr7eng.png" alt="Diagram of SSH connection flow: client and server connected through an encrypted tunnel" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Installing the SSH Server
&lt;/h2&gt;

&lt;p&gt;On a fresh Debian or Ubuntu server, the SSH server is usually already installed. Check its status:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is not installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;openssh-server &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then confirm it is running and enabled at boot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;--now&lt;/span&gt; ssh
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
     Active: active (running) since Sat 2026-10-17 09:00:00 UTC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The SSH server listens on &lt;strong&gt;port 22&lt;/strong&gt; by default. Verify it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ss &lt;span class="nt"&gt;-tlnp&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=812,fd=3))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note on Ubuntu:&lt;/strong&gt; Since Ubuntu 22.10, the service may be named &lt;code&gt;ssh.socket&lt;/code&gt; instead of &lt;code&gt;ssh.service&lt;/code&gt; (socket activation). The commands above work either way, but if you ever wonder why &lt;code&gt;sshd&lt;/code&gt; is not listed as a running service, that is why.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 2: Connecting for the First Time
&lt;/h2&gt;

&lt;p&gt;From your client machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh yeasin@203.0.113.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The authenticity of host '203.0.113.10' can't be established.
ED25519 key fingerprint is SHA256\:xxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
yeasin@203.0.113.10's password:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter the password, and you are in. If you can ping the server but the connection is refused, the most common cause is a &lt;strong&gt;firewall&lt;/strong&gt; — which brings us to an important step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Debian, &lt;code&gt;ufw&lt;/code&gt; may not be installed; install it with &lt;code&gt;sudo apt install ufw&lt;/code&gt;. Without this rule, remote SSH traffic never reaches the server.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3: Key-Based Authentication (Do This First)
&lt;/h2&gt;

&lt;p&gt;Passwords can be guessed, reused, or leaked. &lt;strong&gt;SSH keys solve this.&lt;/strong&gt; A key pair consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;private key&lt;/strong&gt; (&lt;code&gt;~/.ssh/id_ed25519&lt;/code&gt;) — never leaves your machine. Never share it, never copy it to a server.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;public key&lt;/strong&gt; (&lt;code&gt;~/.ssh/id_ed25519.pub&lt;/code&gt;) — safe to share; you place it on every server you want to access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The server can verify you own the private key without you ever sending it. That is the whole trick: the private key proves your identity without ever traveling over the network.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffxpo5c0n00rdqa0n2hkq.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffxpo5c0n00rdqa0n2hkq.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate a key pair
&lt;/h3&gt;

&lt;p&gt;On your &lt;strong&gt;client&lt;/strong&gt; machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"yeasin@laptop"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/yeasin/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Your identification has been saved in /home/yeasin/.ssh/id_ed25519
Your public key has been saved in /home/yeasin/.ssh/id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-t ed25519&lt;/code&gt; — the modern, fast, and secure key type. Prefer it over RSA.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;passphrase&lt;/strong&gt; protects your private key if your laptop is stolen. Recommended.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Copy the public key to the server
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-copy-id yeasin@203.0.113.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is it. Log in again and you will not be asked for a password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh yeasin@203.0.113.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; If &lt;code&gt;ssh-copy-id&lt;/code&gt; is unavailable (for example on Termux), do it manually by appending your public key to the server's &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt; file. Make sure the &lt;code&gt;.ssh&lt;/code&gt; directory has permission &lt;code&gt;700&lt;/code&gt; and the file has &lt;code&gt;600&lt;/code&gt; — SSH ignores keys if the permissions are too open.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Step 4: Understanding and Configuring sshd
&lt;/h2&gt;

&lt;p&gt;All server-side configuration lives in one file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before changing anything, create a backup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After every change, test your configuration &lt;strong&gt;before restarting&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;sshd &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No output means everything is fine. Then apply the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Never close your current SSH session while testing new SSH settings. Keep it open, open a &lt;strong&gt;second&lt;/strong&gt; terminal, and confirm you can still log in. If you locked yourself out, your open session is your rescue line.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The most important settings
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;th&gt;Safe value&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Port 22&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;e.g. &lt;code&gt;Port 2222&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Changes the port scanners expect&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PermitRootLogin no&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;no&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Blocks direct root login&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PasswordAuthentication no&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;no&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Disables password login (keys only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PubkeyAuthentication yes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;yes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Enables key-based login&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AllowUsers yeasin deploy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;your users&lt;/td&gt;
&lt;td&gt;Only listed users may connect at all&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxAuthTries 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Limits login attempts per connection&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Port 2222
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
AllowUsers yeasin
MaxAuthTries 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of these lines removes one attack path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PermitRootLogin no&lt;/code&gt; — attackers always try &lt;code&gt;root&lt;/code&gt; first. Even with a good password, you do not want them hammering the most powerful account.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PasswordAuthentication no&lt;/code&gt; — once your keys work, this is the single biggest security upgrade. Nothing can be brute-forced if passwords are not accepted.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AllowUsers&lt;/code&gt; — even a valid password for an unused account (like &lt;code&gt;guest&lt;/code&gt;) is now useless.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; On modern Ubuntu (22.04+), password authentication may be controlled by a drop-in file at &lt;code&gt;/etc/ssh/sshd_config.d/*.conf&lt;/code&gt;, which overrides the main config. Check with &lt;code&gt;grep -ri PasswordAuthentication /etc/ssh/&lt;/code&gt; to make sure your change actually takes effect.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Changing the default port
&lt;/h3&gt;

&lt;p&gt;Changing the port (e.g., &lt;code&gt;Port 2222&lt;/code&gt;) is &lt;strong&gt;security through obscurity&lt;/strong&gt; — it reduces automated bot noise dramatically, but a targeted attacker will scan all ports anyway. Treat it as noise reduction, not real security:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 2222/tcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-p&lt;/span&gt; 2222 yeasin@203.0.113.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Order matters:&lt;/strong&gt; open the firewall for the new port &lt;em&gt;before&lt;/em&gt; restarting &lt;code&gt;sshd&lt;/code&gt;, or you will lock yourself out.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5: The Client-Side Config File
&lt;/h2&gt;

&lt;p&gt;Tired of typing &lt;code&gt;ssh -p 2222 yeasin@203.0.113.10&lt;/code&gt;? SSH has a built-in solution. Create &lt;code&gt;~/.ssh/config&lt;/code&gt; on your client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host myserver
    HostName 203.0.113.10
    User yeasin
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now connecting is simply:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh myserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This also makes &lt;code&gt;scp&lt;/code&gt;, &lt;code&gt;rsync&lt;/code&gt;, and &lt;code&gt;sftp&lt;/code&gt; use the same settings automatically. If you manage more than one server, this file will save you hours.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 6: Extra Hardening for Public Servers
&lt;/h2&gt;

&lt;p&gt;If your server has a public IP, bots are already knocking on port 22 — check for yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;journalctl &lt;span class="nt"&gt;-u&lt;/span&gt; ssh | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; failed | &lt;span class="nb"&gt;tail&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will likely see login attempts for &lt;code&gt;root&lt;/code&gt;, &lt;code&gt;admin&lt;/code&gt;, and &lt;code&gt;test&lt;/code&gt; from IP addresses all over the world. Two more layers stop this completely.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Fail2ban — automatic attacker blocking
&lt;/h3&gt;

&lt;p&gt;Fail2ban watches the logs and bans IPs after repeated failed attempts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;fail2ban &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;--now&lt;/span&gt; fail2ban
&lt;span class="nb"&gt;sudo &lt;/span&gt;fail2ban-client status sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Status
|- Number of matches:  14
|- Currently banned:   2
`- Total banned:        9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Debian and Ubuntu, fail2ban ships with a ready-made &lt;code&gt;sshd&lt;/code&gt; jail; default is 5 failed attempts leading to a 10-minute ban. Adjust it in &lt;code&gt;/etc/fail2ban/jail.local&lt;/code&gt;.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxxm59zb5f8ayy4z5c77v.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxxm59zb5f8ayy4z5c77v.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Firewall — allow only what you need
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw default deny incoming
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw default allow outgoing
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 2222/tcp
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw &lt;span class="nb"&gt;enable
sudo &lt;/span&gt;ufw status verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Before running &lt;code&gt;ufw enable&lt;/code&gt; on a remote server, make sure your SSH port is allowed. Locking yourself out of a remote machine is a rite of passage — but not one you need to experience.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Common Mistakes and Troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. "Connection refused"&lt;/strong&gt;&lt;br&gt;
The server is reachable, but nothing is listening on that port. Check: is &lt;code&gt;ssh&lt;/code&gt; running (&lt;code&gt;sudo systemctl status ssh&lt;/code&gt;)? Is the firewall allowing the port? Are you connecting to the right port?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. "Connection timed out"&lt;/strong&gt;&lt;br&gt;
Packets are not reaching the server. Check the IP address, cloud provider security groups (AWS/GCP/DigitalOcean firewalls are separate from &lt;code&gt;ufw&lt;/code&gt;), and any network firewall in between.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Key login silently falls back to password&lt;/strong&gt;&lt;br&gt;
Usually permissions. On the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;700 ~/.ssh
&lt;span class="nb"&gt;chmod &lt;/span&gt;600 ~/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And check the logs — they tell you exactly why a login failed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;journalctl &lt;span class="nt"&gt;-u&lt;/span&gt; ssh &lt;span class="nt"&gt;-n&lt;/span&gt; 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Locked yourself out after changing the port&lt;/strong&gt;&lt;br&gt;
This is why you never close the working session during changes. If it does happen: on a VPS, use the provider's web console to fix &lt;code&gt;sshd_config&lt;/code&gt;; on a local machine, plug in a keyboard and monitor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. "Too many authentication failures"&lt;/strong&gt;&lt;br&gt;
Your client may be offering many keys. Fix it in &lt;code&gt;~/.ssh/config&lt;/code&gt; with &lt;code&gt;IdentitiesOnly yes&lt;/code&gt; on that host, so only the right key is offered.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSH&lt;/strong&gt; is the encrypted standard for remote administration — everything you type and transfer is protected end to end.&lt;/li&gt;
&lt;li&gt;Install the server with &lt;code&gt;openssh-server&lt;/code&gt;, and immediately allow it through &lt;code&gt;ufw&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Replace password login with &lt;strong&gt;ed25519 key pairs&lt;/strong&gt; as soon as possible — it is both more secure and more convenient.&lt;/li&gt;
&lt;li&gt;Harden the server in &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt;: &lt;code&gt;PermitRootLogin no&lt;/code&gt;, &lt;code&gt;PasswordAuthentication no&lt;/code&gt;, and &lt;code&gt;AllowUsers&lt;/code&gt; for your accounts.&lt;/li&gt;
&lt;li&gt;Always test with &lt;code&gt;sshd -t&lt;/code&gt; and keep your current session open while applying changes.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;~/.ssh/config&lt;/code&gt; on the client to turn long commands into &lt;code&gt;ssh myserver&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add &lt;strong&gt;fail2ban&lt;/strong&gt; on public servers; bots are already trying your door.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remote access is the gateway skill: once SSH feels natural, managing servers, deploying applications, and automating infrastructure all start from that same &lt;code&gt;ssh&lt;/code&gt; command.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ssh</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Linux File System Structure and Navigation</title>
      <dc:creator>Yeasin's </dc:creator>
      <pubDate>Sun, 11 Oct 2026 17:55:00 +0000</pubDate>
      <link>https://dev.to/yeasin4745/linux-file-system-structure-and-navigation-lb0</link>
      <guid>https://dev.to/yeasin4745/linux-file-system-structure-and-navigation-lb0</guid>
      <description>&lt;p&gt;Every Linux journey starts at the same place: the root directory, written as a single forward slash (&lt;code&gt;/&lt;/code&gt;). Unlike Windows, which scatters files across multiple drives like &lt;code&gt;C:\&lt;/code&gt; and &lt;code&gt;D:\&lt;/code&gt;, Linux organizes &lt;strong&gt;everything&lt;/strong&gt; into one unified tree. Your USB drive, your configuration files, your terminal, even your running processes — they all live somewhere inside that one tree.&lt;/p&gt;

&lt;p&gt;Understanding this structure is not optional knowledge. When an application fails to start, when a disk fills up, or when a security audit asks "who owns this file," the answer is almost always found by navigating the file system confidently. In this article, we'll walk through the Linux directory hierarchy from the top down, then master the commands that let you move through it efficiently.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Filesystem Hierarchy Standard (FHS)
&lt;/h2&gt;

&lt;p&gt;Linux distributions follow a shared layout called the &lt;strong&gt;Filesystem Hierarchy Standard (FHS)&lt;/strong&gt;, maintained by the Linux Foundation. The FHS defines what each major directory should contain, which means a script you write on Debian will very likely work the same way on Ubuntu, Fedora, or Arch — because &lt;code&gt;/etc&lt;/code&gt; means the same thing everywhere.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The FHS describes conventions, not strict laws. Some distributions and tools make small deviations, but the core layout described below is consistent across virtually all modern Linux systems.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  The Root Directory (&lt;code&gt;/&lt;/code&gt;) and Its Key Subdirectories
&lt;/h2&gt;

&lt;p&gt;The top of the entire file system is &lt;code&gt;/&lt;/code&gt; (pronounced "root"). Everything else sits underneath it. Let's look at the directories you'll interact with most often.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/home&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Personal user directories (e.g., &lt;code&gt;/home/yeasin&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/root&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Home directory of the root (administrator) user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;System-wide configuration files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/var&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Variable data: logs, caches, spool files, databases&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/usr&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;User programs, libraries, documentation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/tmp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Temporary files, usually cleared on reboot&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/dev&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Device files representing hardware&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/proc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Virtual filesystem exposing kernel and process info&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/boot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Kernel and boot loader files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/opt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Optional/third-party software&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/mnt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Temporary mount point for manually mounted filesystems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/media&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auto-mounted removable media (USB drives, DVDs)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;/bin&lt;/code&gt;, &lt;code&gt;/sbin&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Essential user and administrator binaries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/lib&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Shared libraries and kernel modules&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/srv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Data served by the system (e.g., web or FTP content)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/run&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Runtime data since boot (process IDs, sockets)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/home&lt;/code&gt; — Your Personal Space
&lt;/h3&gt;

&lt;p&gt;Each regular user gets a directory here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /home
&lt;span class="c"&gt;# output:&lt;/span&gt;
&lt;span class="c"&gt;# yeasin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your documents, downloads, and personal configuration files (the "dotfiles" like &lt;code&gt;~/.bashrc&lt;/code&gt;) all live under &lt;code&gt;/home/yourusername&lt;/code&gt;. This is the only directory where a normal user should freely create and delete files.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/etc&lt;/code&gt; — The Control Room
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;/etc&lt;/code&gt; holds plain-text configuration files for the entire system. This is where you'll go to change hostname settings, configure SSH, or edit system-wide shell behavior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /etc | &lt;span class="nb"&gt;head&lt;/span&gt;
&lt;span class="c"&gt;# output (partial):&lt;/span&gt;
&lt;span class="c"&gt;# hostname&lt;/span&gt;
&lt;span class="c"&gt;# hosts&lt;/span&gt;
&lt;span class="c"&gt;# fstab&lt;/span&gt;
&lt;span class="c"&gt;# ssh&lt;/span&gt;
&lt;span class="c"&gt;# passwd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Editing files in &lt;code&gt;/etc&lt;/code&gt; affects the whole system. A typo in a file like &lt;code&gt;/etc/fstab&lt;/code&gt; can prevent your system from booting. Always back up a config file before modifying it:&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/fstab /etc/fstab.bak
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/var&lt;/code&gt; — Data That Changes
&lt;/h3&gt;

&lt;p&gt;The name stands for "variable" — data that grows and changes while the system runs. The most important subdirectory for daily administration is &lt;code&gt;/var/log&lt;/code&gt;, where the system writes its logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /var/log
&lt;span class="c"&gt;# output (partial):&lt;/span&gt;
&lt;span class="c"&gt;# auth.log&lt;/span&gt;
&lt;span class="c"&gt;# syslog&lt;/span&gt;
&lt;span class="c"&gt;# dmesg&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When something breaks, &lt;code&gt;/var/log&lt;/code&gt; is usually the first place to investigate.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/tmp&lt;/code&gt; — Use It, Don't Trust It
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;/tmp&lt;/code&gt; is world-writable and intended for short-lived files. On most modern distributions (including Debian and Ubuntu using &lt;code&gt;systemd&lt;/code&gt;), its contents are cleared on every reboot. Never store anything there that you want to keep.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/proc&lt;/code&gt; and &lt;code&gt;/dev&lt;/code&gt; — Files That Aren't Files
&lt;/h3&gt;

&lt;p&gt;This is where Linux gets interesting. &lt;code&gt;/proc&lt;/code&gt; is a &lt;strong&gt;virtual filesystem&lt;/strong&gt; — it doesn't exist on disk. The kernel generates its contents in memory to expose live system information as if it were files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /proc/cpuinfo        &lt;span class="c"&gt;# live CPU information&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; /proc/meminfo        &lt;span class="c"&gt;# live memory usage&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; /proc/self            &lt;span class="c"&gt;# info about the currently running shell process&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, &lt;code&gt;/dev&lt;/code&gt; contains &lt;strong&gt;device files&lt;/strong&gt;. Your terminal, your disks, and &lt;code&gt;/dev/null&lt;/code&gt; (the famous "black hole" that discards anything written to it) all appear here as files. This "everything is a file" design is one of Linux's most powerful ideas.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/usr&lt;/code&gt; and the Merged &lt;code&gt;/bin&lt;/code&gt;, &lt;code&gt;/sbin&lt;/code&gt;, &lt;code&gt;/lib&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Historically, &lt;code&gt;/bin&lt;/code&gt; held essential command binaries and &lt;code&gt;/usr/bin&lt;/code&gt; held less critical programs. Modern Debian (since Debian 11 "Bullseye") and Ubuntu (since 19.04) implement &lt;strong&gt;usrmerge&lt;/strong&gt;: &lt;code&gt;/bin&lt;/code&gt;, &lt;code&gt;/sbin&lt;/code&gt;, and &lt;code&gt;/lib&lt;/code&gt; are now symlinks pointing into &lt;code&gt;/usr&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /bin
&lt;span class="c"&gt;# output:&lt;/span&gt;
&lt;span class="c"&gt;# lrwxrwxrwx 1 root root 7 ... /bin -&amp;gt; usr/bin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can still type &lt;code&gt;/bin/bash&lt;/code&gt; and it works — but on modern systems, the real files live under &lt;code&gt;/usr/bin&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Absolute vs. Relative Paths
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;path&lt;/strong&gt; describes a file or directory's location in the tree. There are two kinds:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Absolute path&lt;/strong&gt; — starts from &lt;code&gt;/&lt;/code&gt;. It works from anywhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /var/log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Relative path&lt;/strong&gt; — starts from your current location. It only works relative to where you are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;log        &lt;span class="c"&gt;# only works if you're already inside /var&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two special notations power relative paths:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The current directory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;..&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The parent directory (one level up)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;~&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Your home directory (shortcut)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The previous directory you were in (with &lt;code&gt;cd&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So if you are in &lt;code&gt;/var/log&lt;/code&gt;, then &lt;code&gt;..&lt;/code&gt; means &lt;code&gt;/var&lt;/code&gt;, and &lt;code&gt;../spool&lt;/code&gt; means &lt;code&gt;/var/spool&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Navigation Commands You'll Use Every Day
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;pwd&lt;/code&gt; — Where Am I?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pwd&lt;/code&gt; (print working directory) shows your absolute current location:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
&lt;span class="c"&gt;# output:&lt;/span&gt;
&lt;span class="c"&gt;# /var/log&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The prompt often shows your location, but &lt;code&gt;pwd&lt;/code&gt; is the definitive answer. Use it whenever you're disoriented.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;cd&lt;/code&gt; — Change Directory
&lt;/h3&gt;

&lt;p&gt;The workhorse of navigation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /etc              &lt;span class="c"&gt;# go to /etc (absolute)&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;ssh               &lt;span class="c"&gt;# go to ./ssh (relative)&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ..                &lt;span class="c"&gt;# go up one level&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt;                   &lt;span class="c"&gt;# go to your home directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~                 &lt;span class="c"&gt;# same as above&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; -                 &lt;span class="c"&gt;# go back to the previous directory&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; /home/yeasin/Documents   &lt;span class="c"&gt;# jump anywhere with an absolute path&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A useful habit: after &lt;code&gt;cd -&lt;/code&gt;, bash prints the directory you switched to, which is handy for bouncing between two distant locations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /var/log
&lt;span class="nb"&gt;cd&lt;/span&gt; /etc
&lt;span class="nb"&gt;cd&lt;/span&gt; -
&lt;span class="c"&gt;# output:&lt;/span&gt;
&lt;span class="c"&gt;# /var/log&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;ls&lt;/code&gt; — Look Around
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ls&lt;/code&gt; lists directory contents. Its most useful flags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt;                  &lt;span class="c"&gt;# basic listing&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;               &lt;span class="c"&gt;# long format: permissions, owner, size, date&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;               &lt;span class="c"&gt;# include hidden files (starting with .)&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-la&lt;/span&gt;              &lt;span class="c"&gt;# both combined&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lh&lt;/span&gt;              &lt;span class="c"&gt;# long format with human-readable sizes (K, M, G)&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt;               &lt;span class="c"&gt;# recursive listing of subdirectories&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; /var         &lt;span class="c"&gt;# details of the directory itself, not its contents&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt;              &lt;span class="c"&gt;# sort by modification time, newest first&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lh&lt;/span&gt; /etc/hostname
&lt;span class="c"&gt;# output:&lt;/span&gt;
&lt;span class="c"&gt;# -rw-r--r-- 1 root root 8 Oct 12 09:41 /etc/hostname&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Files whose names begin with a dot (like &lt;code&gt;.bashrc&lt;/code&gt;) are hidden from normal &lt;code&gt;ls&lt;/code&gt; output. Use &lt;code&gt;ls -a&lt;/code&gt; to see them. Most of your shell's personal configuration lives in these files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;tree&lt;/code&gt; — See the Structure at a Glance
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;tree&lt;/code&gt; displays directories as an indented hierarchy — excellent for exploring unfamiliar territory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tree &lt;span class="nt"&gt;-L&lt;/span&gt; 2 /etc/ssh
&lt;span class="c"&gt;# output:&lt;/span&gt;
&lt;span class="c"&gt;# /etc/ssh&lt;/span&gt;
&lt;span class="c"&gt;# ├── moduli&lt;/span&gt;
&lt;span class="c"&gt;# ├── ssh_config&lt;/span&gt;
&lt;span class="c"&gt;# ├── sshd_config&lt;/span&gt;
&lt;span class="c"&gt;# └── ssh_host_rsa_key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Debian/Ubuntu, install it first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;tree
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-L&lt;/code&gt; flag limits the depth, which keeps output readable on large directories.&lt;/p&gt;




&lt;h2&gt;
  
  
  Practical Workflow: Exploring an Unfamiliar System
&lt;/h2&gt;

&lt;p&gt;Here's a realistic scenario: you've just logged into a new server and need to get oriented.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 — Confirm where you are and who you are:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;pwd
whoami&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2 — Check the top-level layout and disk usage:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /
&lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3 — Investigate the logs to see the system's recent activity:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /var/log
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; | &lt;span class="nb"&gt;head&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4 — Check what services are configured:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /etc/ssh
&lt;span class="nb"&gt;cat&lt;/span&gt; /etc/hostname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within a minute, you know the OS layout, available disk space, recent log activity, and configured services — all through navigation alone.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes and Troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mistake 1: Confusing &lt;code&gt;/root&lt;/code&gt; with &lt;code&gt;/&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/&lt;/code&gt; is the root of the entire file system. &lt;code&gt;/root&lt;/code&gt; is the home directory of the administrator user. They look similar but are completely different places.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake 2: Spaces in paths&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /home/yeasin/My Documents
&lt;span class="c"&gt;# bash: cd: too many arguments&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The shell splits arguments at spaces. Quote the path instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"/home/yeasin/My Documents"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mistake 3: Assuming &lt;code&gt;.&lt;/code&gt; is always safe in scripts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A relative path like &lt;code&gt;./script.sh&lt;/code&gt; depends on the current directory. In scripts, prefer absolute paths for anything critical.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake 4: Forgetting that &lt;code&gt;cd&lt;/code&gt; requires execute permission on the target&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To &lt;code&gt;cd&lt;/code&gt; into a directory, you need &lt;strong&gt;execute&lt;/strong&gt; (&lt;code&gt;x&lt;/code&gt;) permission on it — not read. If you get &lt;code&gt;Permission denied&lt;/code&gt; while navigating, check permissions with &lt;code&gt;ls -ld /path/to/dir&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake 5: Editing files in &lt;code&gt;/etc&lt;/code&gt; without a backup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Covered above, but worth repeating: this is the single most common way beginners break a working system.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary and Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Linux uses &lt;strong&gt;one unified tree&lt;/strong&gt; rooted at &lt;code&gt;/&lt;/code&gt;, standardized by the &lt;strong&gt;FHS&lt;/strong&gt; — no drive letters.&lt;/li&gt;
&lt;li&gt;Learn the core directories: &lt;code&gt;/etc&lt;/code&gt; for config, &lt;code&gt;/var/log&lt;/code&gt; for logs, &lt;code&gt;/home&lt;/code&gt; for users, &lt;code&gt;/proc&lt;/code&gt; for live kernel data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Absolute paths&lt;/strong&gt; start with &lt;code&gt;/&lt;/code&gt;; &lt;strong&gt;relative paths&lt;/strong&gt; depend on your current location. &lt;code&gt;..&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt;, and &lt;code&gt;-&lt;/code&gt; are your shortcuts.&lt;/li&gt;
&lt;li&gt;Master &lt;code&gt;pwd&lt;/code&gt;, &lt;code&gt;cd&lt;/code&gt;, &lt;code&gt;ls&lt;/code&gt;, and &lt;code&gt;tree&lt;/code&gt; — these four commands cover 95% of daily navigation.&lt;/li&gt;
&lt;li&gt;Modern Debian and Ubuntu merge &lt;code&gt;/bin&lt;/code&gt;, &lt;code&gt;/sbin&lt;/code&gt;, and &lt;code&gt;/lib&lt;/code&gt; into &lt;code&gt;/usr&lt;/code&gt;; the old paths still work as symlinks.&lt;/li&gt;
&lt;li&gt;Before editing anything in &lt;code&gt;/etc&lt;/code&gt;, make a backup copy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The file system hierarchy rewards curiosity. The next time you're unsure what something does, &lt;code&gt;cd&lt;/code&gt; into it, &lt;code&gt;ls&lt;/code&gt; it, and &lt;code&gt;cat&lt;/code&gt; the files. On Linux, the system rarely hides from you — you just need to know where to walk.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What directory confused you the most when you started with Linux? Share it in the comments — it's probably someone else's question too.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>sysadmi</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Managing Users and Groups in Linux: A Beginner-Friendly Guide</title>
      <dc:creator>Yeasin's </dc:creator>
      <pubDate>Sat, 10 Oct 2026 01:57:40 +0000</pubDate>
      <link>https://dev.to/yeasin4745/managing-users-and-groups-in-linux-a-beginner-friendly-guide-39l6</link>
      <guid>https://dev.to/yeasin4745/managing-users-and-groups-in-linux-a-beginner-friendly-guide-39l6</guid>
      <description>&lt;p&gt;Linux is a multi-user system. That means many people (and many programs) can use the same computer at the same time — but each one gets its own separate identity and its own limits.&lt;/p&gt;

&lt;p&gt;Every person who logs in, and every service that runs in the background, has its own &lt;strong&gt;user account&lt;/strong&gt;. This is how Linux decides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which files you can open&lt;/li&gt;
&lt;li&gt;Which programs you can run&lt;/li&gt;
&lt;li&gt;Who is allowed to use &lt;code&gt;sudo&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Which service can touch which files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to manage a Linux server — or even just understand your own system better — users and groups are the first thing you need to learn.&lt;/p&gt;

&lt;p&gt;In this guide, we will go step by step: what users and groups are, where Linux stores this information, and how to create, change, and delete them safely.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is a User in Linux?
&lt;/h2&gt;

&lt;p&gt;When you create a user, Linux gives that user two important numbers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;UID (User ID)&lt;/strong&gt; — a unique number for the user&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GID (Group ID)&lt;/strong&gt; — a unique number for the user's main group&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your username is just a friendly label. Deep inside, Linux only cares about the numbers.&lt;/p&gt;

&lt;p&gt;For example, when the system checks if you can open a file, it looks at your UID — not your name.&lt;/p&gt;

&lt;p&gt;Linux has three main types of users:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;UID&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Root user&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;root&lt;/code&gt; — the superuser, can do anything&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;System users&lt;/td&gt;
&lt;td&gt;1–999&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;www-data&lt;/code&gt;, &lt;code&gt;mysql&lt;/code&gt;, &lt;code&gt;sshd&lt;/code&gt; — used by services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Normal users&lt;/td&gt;
&lt;td&gt;1000+&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;yeasin&lt;/code&gt;, &lt;code&gt;rahim&lt;/code&gt; — real humans&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; On Debian and Ubuntu, the first normal user you create during installation gets UID 1000.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What Is a Group?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;group&lt;/strong&gt; is a collection of users. It makes sharing easy.&lt;/p&gt;

&lt;p&gt;Example: you have a folder that only the "developers" team should edit. Instead of giving permission to each person one by one, you put them all in one group and give permission to that group.&lt;/p&gt;

&lt;p&gt;Every user has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One primary group&lt;/strong&gt; — usually a group with the same name as the user. New files you create belong to this group.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero or more secondary groups&lt;/strong&gt; — extra groups you join, like &lt;code&gt;sudo&lt;/code&gt; or &lt;code&gt;docker&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Where Linux Stores User Information
&lt;/h2&gt;

&lt;p&gt;All user and group information lives in simple text files inside the &lt;code&gt;/etc&lt;/code&gt; directory:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;What it contains&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/passwd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;All users: name, UID, home folder, shell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/shadow&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Encrypted passwords (only root can read it)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/group&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;All groups and their members&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let's look at one line from &lt;code&gt;/etc/passwd&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /etc/passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yeasin\:x:1000:1000\:MD Yeasin Ali:/home/yeasin:/bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part has a meaning, separated by &lt;code&gt;:&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;yeasin&lt;/code&gt; — username&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; — password is stored in &lt;code&gt;/etc/shadow&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1000&lt;/code&gt; — UID&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1000&lt;/code&gt; — GID of the primary group&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MD Yeasin Ali&lt;/code&gt; — full name / comment&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/home/yeasin&lt;/code&gt; — home directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/bin/bash&lt;/code&gt; — the shell used at login&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Never edit these files by hand with a normal editor. One small mistake can lock you out of your whole system. Always use the commands shown below.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Creating a New User
&lt;/h2&gt;

&lt;p&gt;Debian and Ubuntu have two commands for this, and mixing them up is very common.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 1: &lt;code&gt;adduser&lt;/code&gt; — the easy way (recommended for beginners)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;adduser rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command will ask you a few questions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Adding user 'rahim' ...
Adding new group 'rahim' (1001) ...
Creating home directory '/home/rahim' ...
Copying files from '/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for rahim
Enter the new value, or press ENTER for the default
  Full Name []: Rahim Uddin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. &lt;code&gt;adduser&lt;/code&gt; does everything for you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates the user&lt;/li&gt;
&lt;li&gt;Creates a private group with the same name&lt;/li&gt;
&lt;li&gt;Creates the home directory&lt;/li&gt;
&lt;li&gt;Copies default files from &lt;code&gt;/etc/skel&lt;/code&gt; (like &lt;code&gt;.bashrc&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Sets the password&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; &lt;code&gt;/etc/skel&lt;/code&gt; is the "skeleton" folder. Anything you put there is automatically copied into every new user's home directory. Great for default configs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Option 2: &lt;code&gt;useradd&lt;/code&gt; — the manual way
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;useradd&lt;/code&gt; is the basic, low-level command. By default it does very little — no home directory, no password. You have to ask for everything yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;useradd &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /bin/bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"Rahim Uddin"&lt;/span&gt; rahim
&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Flag&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-m&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create the home directory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-s&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set the login shell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add a full name / comment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-u&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Use a specific UID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-e&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set an expiry date for the account&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; On Debian and Ubuntu, &lt;code&gt;adduser&lt;/code&gt; is friendly and interactive. On other distros (like Fedora), &lt;code&gt;adduser&lt;/code&gt; behaves like &lt;code&gt;useradd&lt;/code&gt;. So it's good to know both commands.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Creating a user for a service (not a human)
&lt;/h3&gt;

&lt;p&gt;When you deploy your own app, never run it as root. Create a special system user for it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;adduser &lt;span class="nt"&gt;--system&lt;/span&gt; &lt;span class="nt"&gt;--group&lt;/span&gt; &lt;span class="nt"&gt;--no-create-home&lt;/span&gt; &lt;span class="nt"&gt;--shell&lt;/span&gt; /usr/sbin/nologin myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your app can run as &lt;code&gt;myapp&lt;/code&gt;, with the minimum possible permissions. If an attacker ever compromises the app, they only get the &lt;code&gt;myapp&lt;/code&gt; account — not root.&lt;/p&gt;




&lt;h2&gt;
  
  
  Changing an Existing User
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;usermod&lt;/code&gt; to change a user's settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add user to a group (secondary group)&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; docker rahim

&lt;span class="c"&gt;# Change the username&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-l&lt;/span&gt; newname oldname

&lt;span class="c"&gt;# Change the home directory and move the files&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-d&lt;/span&gt; /home/newname &lt;span class="nt"&gt;-m&lt;/span&gt; newname

&lt;span class="c"&gt;# Lock the account (user cannot log in)&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-L&lt;/span&gt; rahim

&lt;span class="c"&gt;# Unlock the account&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-U&lt;/span&gt; rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; With &lt;code&gt;-G&lt;/code&gt;, always include &lt;code&gt;-a&lt;/code&gt; (append). &lt;code&gt;sudo usermod -G docker rahim&lt;/code&gt; &lt;strong&gt;without&lt;/strong&gt; &lt;code&gt;-a&lt;/code&gt; removes rahim from all his other groups — including &lt;code&gt;sudo&lt;/code&gt;. That can lock you out of admin access on your own machine. Write it as &lt;code&gt;-aG&lt;/code&gt;, always.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Deleting a User
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Delete the user, keep the home directory&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;userdel rahim

&lt;span class="c"&gt;# Delete the user AND the home directory&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;userdel &lt;span class="nt"&gt;-r&lt;/span&gt; rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before deleting, it's smart to check what files the user still owns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;find / &lt;span class="nt"&gt;-user&lt;/span&gt; rahim 2&amp;gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you delete a user but keep their files, those files will show a number instead of a name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-rw-r--r-- 1 1001 1001 1024 Oct 10 12:00 notes.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;1001&lt;/code&gt; is the old UID. If a new user gets UID 1001 later, they suddenly own those files. So either delete the files or give them to someone else first.&lt;/p&gt;




&lt;h2&gt;
  
  
  Managing Groups
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create a group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;groupadd developers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Delete a group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;groupdel developers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add a user to a group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; developers rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or with &lt;code&gt;gpasswd&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;gpasswd &lt;span class="nt"&gt;-a&lt;/span&gt; rahim developers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remove a user from a group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;gpasswd &lt;span class="nt"&gt;-d&lt;/span&gt; rahim developers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Check which groups a user belongs to
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;groups &lt;/span&gt;rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or get full details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;id &lt;/span&gt;rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uid=1002(rahim) gid=1002(rahim) groups=1002(rahim),27(sudo),1001(developers)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Group changes apply on the &lt;strong&gt;next login&lt;/strong&gt;. If you just added yourself to a group in your current session, log out and log back in for it to take effect.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;sudo&lt;/code&gt; group is special
&lt;/h3&gt;

&lt;p&gt;On Debian and Ubuntu, anyone in the &lt;code&gt;sudo&lt;/code&gt; group can use &lt;code&gt;sudo&lt;/code&gt;. That's the whole mechanism. Want to make someone an admin? Just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Real-World Example: A Shared Project Folder
&lt;/h2&gt;

&lt;p&gt;Let's put it all together with a common real situation.&lt;/p&gt;

&lt;p&gt;Your team has a folder, and three people need to edit the same files. Here's how to set it up cleanly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 — Create a shared group:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;groupadd webteam
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2 — Add the users to the group:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; webteam yeasin
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; webteam rahim
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; webteam karim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3 — Create the folder and give it to the group:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /srv/webproject
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="se"&gt;\:&lt;/span&gt;webteam /srv/webproject
&lt;span class="nb"&gt;sudo chmod&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; 2775 /srv/webproject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What does &lt;code&gt;2775&lt;/code&gt; mean?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;2775&lt;/code&gt; = special bit &lt;code&gt;2&lt;/code&gt; + normal permissions &lt;code&gt;775&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;2&lt;/code&gt; is the &lt;strong&gt;setgid bit&lt;/strong&gt;. It makes every new file inside this folder automatically belong to &lt;code&gt;webteam&lt;/code&gt;, no matter who creates it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;775&lt;/code&gt; means: owner can do everything, group members can do everything, others can only read and open the folder.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4 — Verify:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-ld&lt;/span&gt; /srv/webproject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;drwxrwsr-x 2 root webteam 4096 Oct 10 12:00 /srv/webproject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when rahim creates a file, karim can edit it too — automatically. No manual permission fixing needed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes and Fixes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Using &lt;code&gt;usermod -G&lt;/code&gt; without &lt;code&gt;-a&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This removes the user from all their other groups. Fix it by adding them back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;rahim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Editing &lt;code&gt;/etc/passwd&lt;/code&gt; by hand&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One typo and you may not be able to log in anymore. If you must edit it, use the safe tools:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vipw
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;vipw&lt;/code&gt; checks the file for mistakes before saving.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. "I'm in the group, but I still get permission denied"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Group changes need a new login. Log out and back in — or use this for a quick fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;newgrp docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. A deleted user's files show numbers instead of names&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The UID no longer matches any user. Delete those files, or give them a new owner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; yeasin&lt;span class="se"&gt;\:&lt;/span&gt;yeasin /var/oldstuff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Checking why a user cannot log in&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;getent passwd rahim     &lt;span class="c"&gt;# is the shell set to nologin?&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd &lt;span class="nt"&gt;-S&lt;/span&gt; rahim    &lt;span class="c"&gt;# is the account locked?&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;chage &lt;span class="nt"&gt;-l&lt;/span&gt; rahim     &lt;span class="c"&gt;# any expiry date?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Here are the key points from this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linux identifies every user by a &lt;strong&gt;UID&lt;/strong&gt;, and permissions are always checked against numbers, not names.&lt;/li&gt;
&lt;li&gt;User data lives in &lt;code&gt;/etc/passwd&lt;/code&gt;, &lt;code&gt;/etc/shadow&lt;/code&gt;, and &lt;code&gt;/etc/group&lt;/code&gt; — never edit them by hand.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;code&gt;adduser&lt;/code&gt;&lt;/strong&gt; for easy, interactive user creation on Debian/Ubuntu.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;code&gt;usermod -aG&lt;/code&gt;&lt;/strong&gt; to add users to groups — never forget the &lt;code&gt;-a&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;sudo&lt;/code&gt; group&lt;/strong&gt; is what gives someone admin power.&lt;/li&gt;
&lt;li&gt;Create a &lt;strong&gt;separate system user&lt;/strong&gt; for every service you deploy.&lt;/li&gt;
&lt;li&gt;Use the &lt;strong&gt;setgid bit (&lt;code&gt;2775&lt;/code&gt;)&lt;/strong&gt; on shared folders so group permissions flow automatically to new files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you understand users and groups, everything else in Linux security starts to make sense — because almost every permission question comes down to one simple thing: &lt;em&gt;who is asking, and are they allowed?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ubuntu</category>
      <category>yeasin4745</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Linux File Permissions: Understanding chmod and chown</title>
      <dc:creator>Yeasin's </dc:creator>
      <pubDate>Thu, 08 Oct 2026 12:33:52 +0000</pubDate>
      <link>https://dev.to/yeasin4745/linux-file-permissions-understanding-chmod-and-chown-5e6k</link>
      <guid>https://dev.to/yeasin4745/linux-file-permissions-understanding-chmod-and-chown-5e6k</guid>
      <description>&lt;p&gt;If you have ever seen the error &lt;strong&gt;"Permission denied"&lt;/strong&gt; on a Linux system, you have already met file permissions. Every file and directory on a Linux system has an owner, a group, and a set of permissions that decide exactly who can read, write, or execute it.&lt;/p&gt;

&lt;p&gt;Understanding &lt;code&gt;chmod&lt;/code&gt; and &lt;code&gt;chown&lt;/code&gt; is one of the most practical skills for any Linux user, developer, or system administrator. In this article, we will break it down step by step.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Linux Views File Permissions
&lt;/h2&gt;

&lt;p&gt;Run this command on any file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 deploy deploy 2048 Oct  8 10:24 file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first part (&lt;code&gt;-rw-r--r--&lt;/code&gt;) is the permission string. Let's decode it:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Position&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1st character&lt;/td&gt;
&lt;td&gt;File type (&lt;code&gt;-&lt;/code&gt; = file, &lt;code&gt;d&lt;/code&gt; = directory, &lt;code&gt;l&lt;/code&gt; = symlink)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Characters 2–4&lt;/td&gt;
&lt;td&gt;Permissions for the &lt;strong&gt;owner&lt;/strong&gt; (&lt;code&gt;rw-&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Characters 5–7&lt;/td&gt;
&lt;td&gt;Permissions for the &lt;strong&gt;group&lt;/strong&gt; (&lt;code&gt;r--&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Characters 8–10&lt;/td&gt;
&lt;td&gt;Permissions for &lt;strong&gt;others&lt;/strong&gt; (&lt;code&gt;r--&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each permission has a meaning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;r (read)&lt;/strong&gt; — view the file contents (or list a directory)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;w (write)&lt;/strong&gt; — modify the file (or create/delete files inside a directory)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;x (execute)&lt;/strong&gt; — run the file as a program (or enter a directory)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For directories, &lt;code&gt;x&lt;/code&gt; means "can enter". Without it, you cannot &lt;code&gt;cd&lt;/code&gt; into the directory, even if you can read it.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  chown: Changing Ownership
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;chown&lt;/code&gt; command changes who owns a file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chown &lt;/span&gt;owner&lt;span class="se"&gt;\:&lt;/span&gt;group file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Practical examples:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Change the owner to "deploy"&lt;/span&gt;
&lt;span class="nb"&gt;sudo chown &lt;/span&gt;deploy file.txt

&lt;span class="c"&gt;# Change both owner and group&lt;/span&gt;
&lt;span class="nb"&gt;sudo chown &lt;/span&gt;deploy&lt;span class="se"&gt;\:&lt;/span&gt;deploy file.txt

&lt;span class="c"&gt;# Recursively change ownership of a whole directory&lt;/span&gt;
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; deploy&lt;span class="se"&gt;\:&lt;/span&gt;deploy /var/www/app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; &lt;code&gt;chown&lt;/code&gt; usually requires &lt;code&gt;sudo&lt;/code&gt;. Be careful with &lt;code&gt;-R&lt;/code&gt; — it changes everything inside the directory, including files you may not expect. A wrong recursive &lt;code&gt;chown&lt;/code&gt; on a system directory can break your system.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  chmod: Changing Permissions
&lt;/h2&gt;

&lt;p&gt;While &lt;code&gt;chown&lt;/code&gt; decides &lt;strong&gt;who&lt;/strong&gt;, &lt;code&gt;chmod&lt;/code&gt; decides &lt;strong&gt;what&lt;/strong&gt; they can do.&lt;/p&gt;

&lt;p&gt;There are two ways to use &lt;code&gt;chmod&lt;/code&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Symbolic Mode (letters)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;u+x script.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;u&lt;/code&gt; = owner (user), &lt;code&gt;g&lt;/code&gt; = group, &lt;code&gt;o&lt;/code&gt; = others, &lt;code&gt;a&lt;/code&gt; = all&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt; adds a permission, &lt;code&gt;-&lt;/code&gt; removes it, &lt;code&gt;=&lt;/code&gt; sets it exactly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;u+x script.sh       &lt;span class="c"&gt;# Owner can execute&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;g-w file.txt        &lt;span class="c"&gt;# Remove write from group&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;r file.txt        &lt;span class="c"&gt;# Everyone can only read&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;&lt;span class="nv"&gt;u&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rwx,g&lt;span class="o"&gt;=&lt;/span&gt;rx,o&lt;span class="o"&gt;=&lt;/span&gt; file.txt  &lt;span class="c"&gt;# Full control for owner, read+execute for group, nothing for others&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Numeric (Octal) Mode
&lt;/h3&gt;

&lt;p&gt;Each permission has a value:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;r&lt;/code&gt; = 4&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;w&lt;/code&gt; = 2&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; = 1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You add them up for each category (owner, group, others):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Number&lt;/th&gt;
&lt;th&gt;Permission&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;rwx (4+2+1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;rw- (4+2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;r-x (4+1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;r--&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;---&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;755 script.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Owner:&lt;/strong&gt; 7 → read, write, execute&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Group:&lt;/strong&gt; 5 → read, execute&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Others:&lt;/strong&gt; 5 → read, execute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common real-world values:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;644 file.txt      &lt;span class="c"&gt;# Normal file: owner reads/writes, everyone else reads&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;755 script.sh     &lt;span class="c"&gt;# Executable script or open directory&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;600 ~/.ssh/id_ed25519   &lt;span class="c"&gt;# Private SSH key: only owner can read/write&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;700 ~/.ssh        &lt;span class="c"&gt;# SSH directory: only owner has full access&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; The &lt;code&gt;600&lt;/code&gt; permission on SSH private keys is not optional. &lt;code&gt;ssh&lt;/code&gt; will refuse to use a private key that others can read.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  A Real-World Scenario
&lt;/h2&gt;

&lt;p&gt;Imagine you deploy a web app on an Ubuntu server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; www-data&lt;span class="se"&gt;\:&lt;/span&gt;www-data /var/www/app
&lt;span class="nb"&gt;sudo chmod&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; 755 /var/www/app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;www-data&lt;/code&gt; is the user the web server runs as on Debian/Ubuntu.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;755&lt;/code&gt; lets the web server read and use the files, while other users can read but not modify them.&lt;/li&gt;
&lt;li&gt;Secrets like &lt;code&gt;.env&lt;/code&gt; should be locked down further:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chmod &lt;/span&gt;640 /var/www/app/.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the everyday reality of permissions: &lt;strong&gt;give the minimum access needed, and nothing more&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes and Troubleshooting
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;chmod 777&lt;/code&gt; as a "fix"&lt;/strong&gt; — It makes the file writable by everyone. It often "works", but it is a security hole. Almost always, the correct answer is proper ownership, not 777.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting &lt;code&gt;-R&lt;/code&gt; on directories&lt;/strong&gt; — &lt;code&gt;chmod 644 mydir&lt;/code&gt; changes the directory itself, not its contents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Removing &lt;code&gt;x&lt;/code&gt; from a directory&lt;/strong&gt; — You lose the ability to enter it, even as the owner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ownership vs permission confusion&lt;/strong&gt; — If you own a file, you can change its permissions even without write access to the file itself.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Quick diagnostic habit:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; file.txt        &lt;span class="c"&gt;# Who owns it? What are the permissions?&lt;/span&gt;
&lt;span class="nb"&gt;id&lt;/span&gt;                    &lt;span class="c"&gt;# What groups am I in?&lt;/span&gt;
namei &lt;span class="nt"&gt;-l&lt;/span&gt; /var/www/app/index.html   &lt;span class="c"&gt;# Check permissions on every level of the path&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;namei -l&lt;/code&gt; trick is underrated — "Permission denied" can come from any parent directory in the path, not just the file itself.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Every file has an &lt;strong&gt;owner&lt;/strong&gt;, a &lt;strong&gt;group&lt;/strong&gt;, and &lt;strong&gt;others&lt;/strong&gt;, each with &lt;code&gt;r&lt;/code&gt;, &lt;code&gt;w&lt;/code&gt;, and &lt;code&gt;x&lt;/code&gt; permissions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;chown&lt;/code&gt; changes &lt;strong&gt;who&lt;/strong&gt; owns a file; &lt;code&gt;chmod&lt;/code&gt; changes &lt;strong&gt;what&lt;/strong&gt; they can do.&lt;/li&gt;
&lt;li&gt;Symbolic mode (&lt;code&gt;u+x&lt;/code&gt;) is readable; numeric mode (&lt;code&gt;755&lt;/code&gt;) is compact and fast.&lt;/li&gt;
&lt;li&gt;Follow the principle of least privilege: give the minimum permission required.&lt;/li&gt;
&lt;li&gt;Avoid &lt;code&gt;chmod 777&lt;/code&gt;. Diagnose with &lt;code&gt;ls -l&lt;/code&gt;, &lt;code&gt;id&lt;/code&gt;, and &lt;code&gt;namei -l&lt;/code&gt; instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once this clicks, "Permission denied" stops being a mystery and becomes a simple question: &lt;em&gt;who owns this file, and what are they allowed to do?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>chmod</category>
      <category>sysadmin</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Linux Server User Management: A Complete Practical Guide</title>
      <dc:creator>Yeasin's </dc:creator>
      <pubDate>Wed, 07 Oct 2026 13:18:35 +0000</pubDate>
      <link>https://dev.to/yeasin4745/linux-server-user-management-a-complete-practical-guide-34bk</link>
      <guid>https://dev.to/yeasin4745/linux-server-user-management-a-complete-practical-guide-34bk</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Every Linux server, whether it hosts a small personal project or a large-scale production application, depends on one fundamental administrative task: user management. Properly managed users and groups are the first line of defense for your server's security, and they form the foundation of a well-organized, maintainable system.&lt;/p&gt;

&lt;p&gt;When I first started working with Linux servers, user management seemed like a simple topic — just create a user, set a password, and move on. In practice, it is much more than that. Understanding how users, groups, permissions, and privileges work together is essential for anyone who administers a server, whether you are a DevOps engineer, a backend developer deploying your first application, or a student building a home lab.&lt;/p&gt;

&lt;p&gt;In this article, I will walk you through everything you need to know about user management on a Linux server: creating and deleting users, managing groups, assigning sudo privileges, securing SSH access, and following industry best practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why User Management Matters
&lt;/h2&gt;

&lt;p&gt;Before diving into commands, it is important to understand why this topic deserves your attention:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Each user account is a potential entry point. Unused accounts, weak passwords, and excessive privileges are among the most common ways servers get compromised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accountability:&lt;/strong&gt; When every action can be traced back to a specific user, auditing and troubleshooting become far easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Least privilege:&lt;/strong&gt; Users should only have the access they actually need — no more, no less.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration:&lt;/strong&gt; Groups allow teams to share files and resources safely without exposing them to everyone else.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Understanding Users in Linux
&lt;/h2&gt;

&lt;p&gt;In Linux, every user is identified by two values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Username:&lt;/strong&gt; The human-readable name used to log in (for example, &lt;code&gt;yeasin&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UID (User ID):&lt;/strong&gt; The numeric identifier the system actually uses internally. Regular users typically start at &lt;code&gt;1000&lt;/code&gt;, while system accounts use lower values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;User information is stored in a few key files:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/passwd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores usernames, UIDs, home directories, and default shells&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/shadow&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores encrypted passwords and password aging policies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/group&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores group names, GIDs, and group memberships&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/etc/sudoers&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines which users or groups may run commands with &lt;code&gt;sudo&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You should never edit these files directly with a text editor. Instead, use the dedicated commands covered below, which handle locking and validation for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Users
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Adding a New User
&lt;/h3&gt;

&lt;p&gt;The standard command to create a user is &lt;code&gt;useradd&lt;/code&gt;, but on most modern distributions, &lt;code&gt;adduser&lt;/code&gt; is a friendlier, interactive alternative.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;adduser yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command automatically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates the user,&lt;/li&gt;
&lt;li&gt;Assigns a UID,&lt;/li&gt;
&lt;li&gt;Creates a home directory at &lt;code&gt;/home/yeasin&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;Copies default configuration files into the home directory,&lt;/li&gt;
&lt;li&gt;Prompts you to set a password and optional details.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your distribution only ships the low-level &lt;code&gt;useradd&lt;/code&gt; command, create a user with a home directory and Bash shell like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;useradd &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /bin/bash yeasin
&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;-m&lt;/code&gt; flag creates the home directory, and &lt;code&gt;-s&lt;/code&gt; sets the default shell.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Verifying the User
&lt;/h3&gt;

&lt;p&gt;Confirm that the user was created correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;id &lt;/span&gt;yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uid=1001(yeasin) gid=1001(yeasin) groups=1001(yeasin)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Managing Passwords and Account Policies
&lt;/h2&gt;

&lt;p&gt;A strong password policy is a core part of server security. Set or change a user's password with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;passwd yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also enforce password aging so that passwords expire periodically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;chage &lt;span class="nt"&gt;-M&lt;/span&gt; 90 yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This forces the user to change their password every 90 days. To review a user's password policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;chage &lt;span class="nt"&gt;-l&lt;/span&gt; yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For production servers, consider requiring strong passwords using PAM (Pluggable Authentication Modules) configuration, and always prefer key-based authentication over passwords for remote access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with Groups
&lt;/h2&gt;

&lt;p&gt;Groups make permission management dramatically simpler. Instead of assigning permissions to users one by one, you assign them to a group once.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Creating a Group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;groupadd developers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Adding a User to a Group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; developers yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-aG&lt;/code&gt; flags are critical: &lt;code&gt;-a&lt;/code&gt; appends the user to the group without removing them from other groups, and &lt;code&gt;-G&lt;/code&gt; specifies the group. If you omit &lt;code&gt;-a&lt;/code&gt;, the user will be removed from all their other secondary groups — a common and painful mistake.&lt;/p&gt;

&lt;p&gt;Verify group membership after the user logs in again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;groups &lt;/span&gt;yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Deleting a Group
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;groupdel developers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Granting Sudo Privileges
&lt;/h2&gt;

&lt;p&gt;Sometimes a user needs administrative rights. There are two recommended ways to grant them.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Using the Sudo Group
&lt;/h3&gt;

&lt;p&gt;On Ubuntu and Debian, members of the &lt;code&gt;sudo&lt;/code&gt; group automatically receive administrative privileges:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On CentOS, RHEL, and Fedora, the equivalent group is called &lt;code&gt;wheel&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; wheel yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Using a Custom Sudoers File
&lt;/h3&gt;

&lt;p&gt;For fine-grained control, create a dedicated sudoers file for the user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;visudo &lt;span class="nt"&gt;-f&lt;/span&gt; /etc/sudoers.d/yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this line to allow full access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yeasin ALL=(ALL:ALL) ALL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always use &lt;code&gt;visudo&lt;/code&gt; when editing sudo configuration. It validates the syntax before saving, which prevents you from accidentally locking yourself out of administrative access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Locking, Unlocking, and Deleting Users
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Locking an Account
&lt;/h3&gt;

&lt;p&gt;When someone leaves a team, disable their account immediately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-L&lt;/span&gt; yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlock it later if needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-U&lt;/span&gt; yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Deleting a User
&lt;/h3&gt;

&lt;p&gt;To remove a user along with their home directory and mail spool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;userdel &lt;span class="nt"&gt;-r&lt;/span&gt; yeasin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Double-check the username before running this command, because deletion is permanent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Securing SSH Access
&lt;/h2&gt;

&lt;p&gt;User management on a server goes hand in hand with SSH security. A few essential practices:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Use Key-Based Authentication
&lt;/h3&gt;

&lt;p&gt;Generate a key pair on your local machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the public key to the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-copy-id yeasin@your-server-ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Disable Root Login and Password Authentication
&lt;/h3&gt;

&lt;p&gt;Edit the SSH daemon configuration at &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PermitRootLogin no
PasswordAuthentication no
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then restart the SSH service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart sshd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Restrict Which Users Can Log In
&lt;/h3&gt;

&lt;p&gt;Allow only specific users to connect over SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AllowUsers yeasin deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep an SSH session open while testing configuration changes, so you never lock yourself out of your own server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices Checklist
&lt;/h2&gt;

&lt;p&gt;To summarize the habits of a well-managed server:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a separate user for every person and every service; never share accounts.&lt;/li&gt;
&lt;li&gt;Disable root login over SSH and use &lt;code&gt;sudo&lt;/code&gt; for administrative tasks instead.&lt;/li&gt;
&lt;li&gt;Prefer key-based authentication over password authentication.&lt;/li&gt;
&lt;li&gt;Apply the principle of least privilege: grant only the access a user actually needs.&lt;/li&gt;
&lt;li&gt;Regularly audit accounts with &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;lastlog&lt;/code&gt;, and &lt;code&gt;/var/log/auth.log&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Lock or delete accounts as soon as they are no longer needed.&lt;/li&gt;
&lt;li&gt;Enforce password aging policies with &lt;code&gt;chage&lt;/code&gt; where key-based login is not possible.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;User management may appear to be a basic administrative chore, but it is genuinely one of the most important pillars of Linux server security. A server with carefully controlled users, groups, and privileges is dramatically harder to compromise, far easier to audit, and much simpler to maintain over time.&lt;/p&gt;

&lt;p&gt;The commands in this guide are the same ones used daily by professional system administrators. Practice them on a virtual machine or a cloud instance, break things safely, and rebuild your understanding from the ground up. The more comfortable you become with user management, the more confident you will feel running production servers.&lt;/p&gt;

&lt;p&gt;If you found this guide helpful, consider saving it for reference and sharing it with others who are learning Linux administration.&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>security</category>
      <category>ubuntu</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
