Add new guide, and 2024 guide section

develop
Nathan Steel 1 year ago
parent 710bc70069
commit c84b2ea68a

@ -38,6 +38,10 @@
<li><a href="/guides/guide-to-server-hosting.html">Guide to server hosting</a></li> <li><a href="/guides/guide-to-server-hosting.html">Guide to server hosting</a></li>
<li><a href="/guides/web-dev-101.html">Web Development 101</a></li> <li><a href="/guides/web-dev-101.html">Web Development 101</a></li>
</ul> </ul>
<h2>2024</h2>
<ul>
<li><a href="/guides/linux-file-permissions.html">Linux File Permissions</a> - 14/09/2024</li>
</ul>
<h2>2022</h2> <h2>2022</h2>
<ul> <ul>
<li><a href="/guides/webpage-to-website.html">Webpage to website</a> - 22/11/2022</li> <li><a href="/guides/webpage-to-website.html">Webpage to website</a> - 22/11/2022</li>

@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="A guide to adding a free SSL certificate to your website(s) using cerbot, and automatically renewing them">
<meta name="keywords" content="Blog, articles, guide, certbot, SSL, secure certificate, website">
<meta name="author" content="Nathan (Aney) Steel">
<meta name="theme-color" content="white">
<meta name="theme-color" content="black">
<link rel="stylesheet" type="text/css" href="/main.css">
<link rel="icon" type="image/png" href="/images/favicon.svg">
<title>Linux File Permissions</title>
</head>
<body>
<header>
<a href="#main" class="vh">Jump directly to main content</a>
<h1>Linux File Permissions</h1>
<input id="burger-toggle" type="checkbox"/>
<label class="burger-container" for="burger-toggle"><div class="burger"></div><span class="sr">Burger menu</span></label>
<hr/>
<nav>
<a href="/">home</a>
<a href="/about.html">about</a>
<a href="/projects.html">projects</a>
<a href="/blog/">blog</a>
<a href="/sitemap.html">misc</a>
<a href="/support.html">support</a>
</nav>
<hr/>
</header>
<main id="main">
<section>
<p>Having multiple users and groups with access to the same linux PC/server is great, but not everyone should have access to everything, eh.</p>
<p>For this, we'll use an example file, and switch ownership between root, and our user. So run the following snippet if your're using this as a tutorial, otherwise just read on.</p>
<pre><code>mkdir ~/permsExample && cd ~/permsExample && sudo touch FILENAME</code></pre>
<h2>Basic File Permisssion Breakdown</h2>
<p>For certain things, such as computers with only a few users/groups this works splendid.</p>
<p>If we run a <code>ls -l FILENAME</code>, we'll see something along the lines of the below.</p>
<pre><code>-rw-r--r-- 1 root root 0 Sep 14 13:02 FILENAME</code></pre>
<p><code>-rw-r--r--</code> being the permissions for User, Group, and Others which can be rwx for read, write, and executable permissions. Set in groups of 3s for User/Group/Others respectively.</p>
<p><code>root root</code> refers to the owner user and owner group.</p>
<h2>Set User/Group Ownership</h2>
<p>Each file, and directory within UNIX has an owner user, and owner group.<br>
By default when you create a file your user will be the owner, and your usergroup will be the owner group.</p>
<p>This can be changed with a simple command (that may need to be run with sudo).</p>
<pre><code>chown USER FILENAME
chown :GROUP FILENAME
chown USER:GROUP FILENAME</code></pre>
<p>The above snippet has the <code>chown</code> command run three different times with different purposes.
The first is to change just the owner user, second to change just the owner group,
and third to change both at the same time.</p>
<p>So to change the owner user for FILENAME to our own user, we'd run <code>sudo chown $USER FILENAME</code>, then verify the change by running <code>ls -l FILENAME</code>.</code></p>
<h2>Set Permissions for User/Group/Others</h2>
<p>Now we'll take a look at the file permissions that will affect the owners, and all other users.</p>
<p>If we look back at the <code>ls -l FILENAME</code> mentioned earlier you'll recall the brief <code>-rw-r--r--</code> mention.</p>
<h3>Intro to the rw-r--r-- meaning</h3>
<p>There are 10 dashes (-) that can be set, ignoring the first for now leaves us with 9, seperated by 3s.</p>
<p>The first group of three <code>rw-</code> in this example shows that the owner user has read/write permissons, but no executable permissions.
<br>The second group <code>r--</code>, shows the owner group only has read permissions, not write/executable permissions.
<br>And the third group <code>r--</code>, shows that other users have read permissions, but cannot write/execute the files.</p>
<h3>Set permissions</h3>
<p>The below commands will set read, write, and execute permissions for the user, and group and give all other users read permissions for filename.file.</p>
<pre><code>chmod ug+rwx FILENAME
chmod o+r FILENAME</code></pre>
<p>First thing after the <code>chmod</code> command (and a space) can be any combination of <code>ugoa</code>. Referring to user, group, other, and all.</p>
<p>Second, immediately after the letters can be one of <code>+,-,=</code> which are used to add, remove, or set (exact) permissions.</p>
<p>Third, any combination of <code>rwx</code> for read, write, executable permissions.</p>
<p>Follow this up with a space and the file/directory name and poof, permissions are set. If you'd like to set permissions for all files within a directory (and not just new ones created), also add a <code> -R</code> at the end of the command.</code></p>
<h4>Set permissions by number</h4>
<p>Many guides, examples, snippets, and such do not give their demonstration of setting permissions in the same manner as above, instead they'll use numbers, such as the below.</p>
<pre><code>chmod 755 FILENAME</code></pre>
<p>This chmod command will give rwx permissions to the owner user, and rx to the owner group, and other.</p>
<p>The numbers are much simpler to understand than you'd think:
<br>4 = Read
<br>2 = Write
<br>1 = Execute/executable
</p>
<p>These numbers get added up and grant those permissions to the users. So 7 = rwx, 6 = rw, 5 = rx, 3 = wx, 0 = no permissions, etc.</p>
<p>You'll also spot that there are 3 numbers, 7,5,5. These are for user, group, and other respectively. So each rwx number up to 7 sets the permissions for different users.</p>
<h3>Chmod directories</h3>
<p>The <code>chmod</code> command can also be used on directories. The following example will give all permissions to all users for that directory, and all its child files/directories.</p>
<pre><code>chmod a=rwx directoryName -R</code></pre>
</section>
</main>
<footer>
<hr/>
<p>Written by <a href="https://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
</footer>
</body>
</html>
Loading…
Cancel
Save