<?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: tuanha</title>
    <description>The latest articles on DEV Community by tuanha (@ha_duytun_0d56e119b446).</description>
    <link>https://dev.to/ha_duytun_0d56e119b446</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3964892%2F0ffcfa0a-6ba0-45dd-9372-5437cf40cad0.jpg</url>
      <title>DEV Community: tuanha</title>
      <link>https://dev.to/ha_duytun_0d56e119b446</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ha_duytun_0d56e119b446"/>
    <language>en</language>
    <item>
      <title>401 Unauthorized Error: Causes and Solutions</title>
      <dc:creator>tuanha</dc:creator>
      <pubDate>Fri, 05 Jun 2026 13:55:26 +0000</pubDate>
      <link>https://dev.to/ha_duytun_0d56e119b446/401-unauthorized-error-causes-and-solutions-4lii</link>
      <guid>https://dev.to/ha_duytun_0d56e119b446/401-unauthorized-error-causes-and-solutions-4lii</guid>
      <description>&lt;p&gt;Are you trying to access a website or call an API, only to be suddenly met with a 401 Unauthorized error? This error indicates that the server has rejected the authentication credentials you provided, or that you failed to provide any credentials at all.&lt;/p&gt;

&lt;p&gt;In this article, I will explain what a 401 error is, list the most common causes, and guide you through four ways to resolve it—ranging from simple fixes to more advanced troubleshooting. Whether you are a regular user or a website administrator, you will find the right solution here.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the 401 Unauthorized Error?
&lt;/h2&gt;

&lt;p&gt;The 401 error is an HTTP status code in the 4xx category (client-side error). When a server returns a 401 code, it is essentially saying: “I need you to authenticate before I can grant access to this resource, but the information you provided is either invalid or missing.”&lt;/p&gt;

&lt;p&gt;It is important to distinguish this: 401 relates to authentication—the server does not yet know who you are. This is fundamentally different from a 500 Internal Server Error, which is a server-side issue.&lt;/p&gt;

&lt;p&gt;Although the official name is “Unauthorized,” its actual meaning is closer to “Unauthenticated.” Put simply, the server is asking: “Who are you? Please prove it.”&lt;/p&gt;

&lt;p&gt;When a browser receives a 401 response, the server also includes a WWW-Authenticate header, which indicates the authentication method it accepts. Examples include Basic Auth (username/password), Bearer Token (used for APIs), or Digest Auth. The browser uses this header to trigger a login popup, or an application will know it needs to resend the request with the correct credentials.&lt;/p&gt;

&lt;p&gt;You may encounter the 401 error in various forms, depending on the server and browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;401 Unauthorized&lt;/li&gt;
&lt;li&gt;HTTP Error 401&lt;/li&gt;
&lt;li&gt;Authorization Required&lt;/li&gt;
&lt;li&gt;Access Denied&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Regardless of how it is displayed, they all mean the same thing: the server requires you to authenticate first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Distinguishing 401 vs. 403 Errors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Many people confuse the 401 error with the 403 Forbidden error. The difference is as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;401 Unauthorized&lt;/strong&gt;: The server does not know who you are. You need to log in or provide valid authentication credentials. Once you have authenticated correctly, you will be granted access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;403 Forbidden&lt;/strong&gt;: The server knows who you are, but you do not have permission to access that specific resource. Logging in again will not help; you must contact the administrator to be granted the necessary permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In simple terms&lt;/strong&gt;: 401 means “not logged in,” while 403 means “logged in, but lack sufficient permissions.” Since the solutions for these are completely different, always identify the error correctly before attempting to fix it.&lt;/p&gt;

&lt;h2&gt;
  
  
  5 Common Causes of the 401 Error
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.Incorrect Login Credentials&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The simplest cause is entering an incorrect username or password. This could be due to a typo, having Caps Lock enabled, or using an outdated password that has since been changed. This is frequently encountered when accessing WordPress admin pages (/wp-admin), cPanel, or other systems that require authentication.&lt;/p&gt;

&lt;p&gt;Additionally, if you are using a password manager, it is possible that it is automatically filling in an outdated password saved previously. Always double-check the auto-filled information before clicking “Login.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Expired Session&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most websites set an expiration time for each login session. If you leave your browser tab idle for too long, the session will expire. At this point, any subsequent requests will be rejected by the server with a 401 status code.&lt;/p&gt;

&lt;p&gt;For example, WordPress defaults to a session duration of approximately 48 hours (or 14 days if you check the “Remember Me” box). For banking or financial applications, the session timeout is typically only 5 to 15 minutes for security reasons. Logging in again is the quickest way to resolve this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Directory Protection with .htpasswd&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On Apache servers, administrators can use an .htaccess file combined with an .htpasswd file to require authentication when accessing a specific directory. If you attempt to access a URL within that directory without entering the correct credentials, the server will return a 401 error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="c"&gt;# Example of .htaccess configuration for directory protection&lt;/span&gt;
&lt;span class="nc"&gt;AuthType&lt;/span&gt; &lt;span class="ss"&gt;Basic&lt;/span&gt;
&lt;span class="nc"&gt;AuthName&lt;/span&gt; "Restricted Area"
&lt;span class="nc"&gt;AuthUserFile&lt;/span&gt; /home/user/.htpasswd
&lt;span class="nc"&gt;Require&lt;/span&gt; valid-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The configuration above requires all visitors to enter a username and password. If the .htpasswd file is corrupted, the AuthUserFile path is incorrect, or the password hash within the file is improperly formatted, the server will return a 401 error to everyone, even if they enter the correct credentials.&lt;/p&gt;

&lt;p&gt;On Nginx, a similar mechanism is used via the auth_basic and auth_basic_user_file directives. The principle is the same; only the configuration syntax differs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Invalid or Expired API Token&lt;/strong&gt;&lt;br&gt;
For applications using REST APIs, a 401 error typically occurs when the access token has expired, been revoked, or is sent with an incorrect format in the Authorization header. This scenario is common when working with the WordPress REST API, third-party services, or mobile apps communicating with a backend API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Example of an API request with a missing or incorrect token
&lt;span class="go"&gt;curl -H "Authorization: Bearer expired_token_here" https://api.example.com/data
&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;Server returns:
&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;HTTP/1.1 401 Unauthorized
&lt;span class="gp"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;: &lt;span class="s2"&gt;"invalid_token"&lt;/span&gt;, &lt;span class="s2"&gt;"message"&lt;/span&gt;: &lt;span class="s2"&gt;"Token has expired"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Readmore :&lt;br&gt;
&lt;a href="https://haduymusic.com/website-knowledge/401-unauthorized-error-causes-and-solutions/" rel="noopener noreferrer"&gt;https://haduymusic.com/website-knowledge/401-unauthorized-error-causes-and-solutions/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>vps</category>
    </item>
    <item>
      <title>High VPS CPU Usage (100%): Causes and Fixes</title>
      <dc:creator>tuanha</dc:creator>
      <pubDate>Thu, 04 Jun 2026 13:50:18 +0000</pubDate>
      <link>https://dev.to/ha_duytun_0d56e119b446/high-vps-cpu-usage-100-causes-and-fixes-1odm</link>
      <guid>https://dev.to/ha_duytun_0d56e119b446/high-vps-cpu-usage-100-causes-and-fixes-1odm</guid>
      <description>&lt;p&gt;When your VPS CPU spikes to 100%, the first symptom is usually a sluggish SSH connection, website timeouts, and even simple commands like ls can lag for several seconds. This situation is very common with VPS hosting, especially when running WordPress or high-traffic web applications.&lt;/p&gt;

&lt;p&gt;The problem is that many administrators immediately think of upgrading their VPS the moment they see 100% CPU usage. In reality, there are many different underlying causes—ranging from heavy MySQL queries and misconfigured PHP-FPM to hidden malware. Understanding the root cause will help you fix the issue properly instead of throwing money out the window.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking the Current CPU Status
&lt;/h2&gt;

&lt;p&gt;The first step is to see exactly where your VPS is bottlenecked. These three commands will give you a quick overview:&lt;/p&gt;

&lt;p&gt;Checking the Load Average with uptime&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;uptime

&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 console"&gt;&lt;code&gt;&lt;span class="go"&gt;12:34:56 up 5 days, 2:15, 2 users, load average: 3.45, 2.89, 1.67

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Load average represents the average number of processes waiting for the CPU over the last 1, 5, and 15 minutes. If your VPS has 2 CPU cores and the load average is above 2.0, it is a clear sign of an overload. In the example above, a load average of 3.45 on a 2-core VPS means the CPU is heavily bottlenecked.&lt;/p&gt;

&lt;p&gt;💡 Tip: Load average &amp;gt; number of CPU cores = VPS is overloaded, immediate action required&lt;/p&gt;

&lt;p&gt;Viewing Real-Time Statistics with the top Command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;top
&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 console"&gt;&lt;code&gt;&lt;span class="go"&gt;top - 12:35:21 up 5 days, 2:15, 2 users, load average: 3.21, 2.95, 1.89
Tasks: 127 total, 4 running, 123 sleeping, 0 stopped, 0 zombie
%Cpu(s): 85.3 us, 12.1 sy, 0.0 ni, 2.1 id, 0.5 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 2048.0 total, 156.4 free, 1654.2 used, 237.4 buff/cache
MiB Swap: 1024.0 total, 890.2 free, 133.8 used. 231.6 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 3429 mysql     20   0   1.2g   456m    12m S  67.3  22.9   8:45.67 mysqld
 1847 www-data  20   0   456m    89m     8m R  18.7   4.5   2:34.12 php-fpm
 1923 www-data  20   0   421m    76m     7m S  12.1   3.8   1:56.34 php-fpm
  982 nginx     20   0   128m    24m     6m S   2.3   1.2   0:45.11 nginx
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The %Cpu(s) line shows the CPU breakdown:&lt;/p&gt;

&lt;p&gt;us (user): 85.3% – User-space processes (MySQL, PHP, Apache…)&lt;br&gt;
sy (system): 12.1% – Kernel/system processes&lt;br&gt;
id (idle): 2.1% – Idle CPU (the lower this is, the more alarming)&lt;br&gt;
wa (wait): 0.5% – Waiting for disk I/O&lt;br&gt;
st (steal): 0.0% – Steal time (CPU time “stolen” from your VPS by the physical host)&lt;br&gt;
A Visual Interface with htop&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;htop
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;htop offers a much cleaner, color-coded interface:&lt;/p&gt;

&lt;p&gt;Green: User processes (normal activity)&lt;br&gt;
Red: System/kernel processes&lt;br&gt;
Gray: Waiting for I/O (disk, network)&lt;br&gt;
Cyan: Steal time (a sign that the VPS host is oversold)&lt;br&gt;
Blue: Low priority processes&lt;br&gt;
⚠️ Note: If you see a lot of red or cyan, it is a sign that you need to investigate further.&lt;/p&gt;
&lt;h2&gt;
  
  
  Distinguishing Between Different Types of CPU Load
&lt;/h2&gt;

&lt;p&gt;Not all 100% CPU scenarios are created equal. By looking closely at the %Cpu(s) line in the top command, you can pinpoint the primary culprit:&lt;/p&gt;

&lt;p&gt;High %us (&amp;gt;70%) – User-Space Applications&lt;br&gt;
This is the most common scenario. The CPU is being heavily consumed by applications running in user-space, such as MySQL, PHP-FPM, Apache, Nginx, or Node.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so     bi     bo   in   cs us sy id wa st
 6  0      0 512000  85532 890140    0    0      2      8   85  156 78 15  7  0  0
 5  1      0 511800  85532 890144    0    0      0      4   92  189 82 12  6  0  0
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Symptoms:&lt;/p&gt;

&lt;p&gt;High r (6, 5): Multiple processes are actively waiting for CPU cycles.&lt;br&gt;
High us + sy (78+15=93%, 82+12=94%): The CPU is working under extreme load.&lt;br&gt;
Low id (7%, 6%): The CPU has virtually zero idle time to rest.&lt;br&gt;
Low wa (0%): No disk or network I/O bottlenecks are present.&lt;br&gt;
Solution: Optimize your applications, tune your database queries, or adjust service configurations.&lt;/p&gt;

&lt;p&gt;High %sy (&amp;gt;30%) – System/Kernel Space&lt;br&gt;
The CPU is being heavily consumed by the operating system kernel, usually due to heavy network I/O, excessive context switching, or driver-related issues.&lt;/p&gt;

&lt;p&gt;Symptoms:&lt;/p&gt;

&lt;p&gt;No single user-space process shows abnormally high CPU usage.&lt;br&gt;
Massive spikes in network traffic (monitored via iotop or iftop).&lt;br&gt;
High rate of context switches (monitored via vmstat).&lt;br&gt;
Solution: Check network traffic, tune kernel parameters, or contact your VPS provider.&lt;/p&gt;

&lt;p&gt;High %wa (&amp;gt;20%) – I/O Wait&lt;br&gt;
The CPU is sitting idle while waiting for disk or network I/O operations to complete. This is not an actual CPU performance issue, but rather a storage bottleneck.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;iotop -ao  #&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;View which processes are reading/writing the most to the disk
&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 console"&gt;&lt;code&gt;&lt;span class="go"&gt;Total DISK READ:  125.67 M/s | Total DISK WRITE:  234.12 M/s
  PID USER     DISK READ  DISK WRITE  SWAPIN      IO    COMMAND
 3429 mysql     89.23 M/s   156.78 M/s   0.00 % 67.23 % mysqld
 2341 root      23.45 M/s    78.90 M/s   0.00 % 23.12 % rsync
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ℹ️ If you see a high %wa, refer to the guide on dealing with high Disk I/O for specific troubleshooting steps.&lt;/p&gt;

&lt;p&gt;High %st (&amp;gt;5%) – Steal Time&lt;br&gt;
Your CPU cycles are being “stolen” by the physical host to serve other virtual machines. This is a telltale sign of an oversold provider or a “noisy neighbor” on the same hardware.&lt;/p&gt;

&lt;p&gt;🚫 Warning: If steal time is above 10%, contact support immediately—this is an infrastructure-level issue.&lt;/p&gt;
&lt;h2&gt;
  
  
  Finding the Process Hogging the CPU
&lt;/h2&gt;

&lt;p&gt;Once you understand the type of load, the next step is to pinpoint exactly which process is “eating” your CPU.&lt;/p&gt;

&lt;p&gt;Using the ps Command to Sort by CPU Usage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;ps aux --sort=-%cpu | head -15

&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 console"&gt;&lt;code&gt;&lt;span class="go"&gt;USER       PID %CPU %MEM    VSZ    RSS TTY      STAT START   TIME COMMAND
mysql     3429 67.3 22.9 1234567 456789 ?      Sl   10:23   8:45 /usr/sbin/mysqld
www-data  1847 18.7  4.5  456789  89012 ?      S    09:15   2:34 php-fpm: pool www
www-data  1923 12.1  3.8  421345  76543 ?      S    09:18   1:56 php-fpm: pool www
www-data  2156  8.9  3.2  398765  65432 ?      S    09:45   1:23 php-fpm: pool www
root      2341  6.7  1.2  234567  23456 ?      D    11:30   0:45 rsync -av /backup/
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reference : &lt;br&gt;
&lt;a href="https://haduymusic.com/server-administration/high-vps-cpu-usage-100-causes-and-fixes/" rel="noopener noreferrer"&gt;https://haduymusic.com/server-administration/high-vps-cpu-usage-100-causes-and-fixes/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>infrastructure</category>
      <category>linux</category>
      <category>performance</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
