{"id":5253,"date":"2026-03-27T12:02:47","date_gmt":"2026-03-27T06:32:47","guid":{"rendered":"https:\/\/qloudhost.com\/blog\/?p=5253"},"modified":"2026-03-27T12:02:50","modified_gmt":"2026-03-27T06:32:50","slug":"how-to-allow-deny-ssh-access-linux","status":"publish","type":"post","link":"https:\/\/qloudhost.com\/blog\/how-to-allow-deny-ssh-access-linux","title":{"rendered":"How to Allow or Deny SSH Access In Linux 2026? &#8211; Complete Guide"},"content":{"rendered":"\n<p>Ever worried someone might access your Linux server without permission?<\/p>\n\n\n\n<p>SSH (Secure Shell) is the lifeline of system administrators. It gives you remote control over Linux servers \u2014 but with great power comes the need for strong control. Do you want to <strong>allow specific users<\/strong> to access your server, or <strong>block unauthorized logins<\/strong>? You\u2019re in the right place.<\/p>\n\n\n\n<p>In this comprehensive guide, we\u2019ll walk you through everything about controlling SSH access in Linux \u2014 whether you want to allow it for select users or deny it entirely. <\/p>\n\n\n\n<p><strong>Let\u2019s dive in.<\/strong> \ud83d\udc47<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What is SSH Access?<\/h2>\n\n\n\n<p>Let\u2019s first understand what SSH really means in simple terms.<\/p>\n\n\n\n<div class=\"wp-block-media-text has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 35%\"><div class=\"wp-block-media-text__content\">\n<p><strong>SSH (Secure Shell)<\/strong> is a protocol used to securely log into a remote system over a network. It encrypts all traffic and allows administrators and developers to execute commands, transfer files, and manage services without needing physical access.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-1024x1024.jpg\" alt=\"What is SSH Access\" class=\"wp-image-5254 size-full\" title=\"\" srcset=\"https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-1024x1024.jpg 1024w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-300x300.jpg 300w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-150x150.jpg 150w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-768x768.jpg 768w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-1536x1536.jpg 1536w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-810x810.jpg 810w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access-1140x1140.jpg 1140w, https:\/\/qloudhost.com\/blog\/wp-content\/uploads\/2025\/06\/What-is-SSH-Access.jpg 2000w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>Whether you\u2019re running a VPS, <a href=\"https:\/\/qloudhost.com\/blog\/what-is-nginx\/\">dedicated server<\/a>, or local Linux machine \u2014 <strong>SSH is the most common remote administration method.<\/strong><\/p>\n\n\n\n<p>By default, most Linux distributions come with OpenSSH installed. Once SSH is enabled and running, it listens on port <code>22<\/code> (unless changed) and can be accessed using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-background\" style=\"background-color:#f0f0f0\">bash<br><br><code>ssh username@hostname<br><\/code><\/pre>\n\n\n\n<p>But to secure it properly, <strong>you need to control who can or cannot log in via SSH.<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to Allow SSH Access in Linux?<\/h2>\n\n\n\n<p>If you&#8217;re setting up a secure environment, granting SSH access only to trusted users is a smart move. This helps minimize security risks and protects critical system resources.<\/p>\n\n\n\n<p>Let\u2019s explore how you can do this step by step.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Add a User for SSH Access<\/h3>\n\n\n\n<p>Before allowing SSH access, make sure the user exists:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo adduser username<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Edit the SSH Configuration File<\/h3>\n\n\n\n<p>SSH settings are managed through the <code>\/etc\/ssh\/sshd_config<\/code> file.<\/p>\n\n\n\n<p>Open the file with your preferred text editor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n<p>Now, look for the directive <code>AllowUsers<\/code>. If it doesn\u2019t exist, add it at the bottom of the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>AllowUsers username1 username2<\/code><\/pre>\n\n\n\n<p>This line will <strong>allow only listed users<\/strong> to connect via SSH.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Restart the SSH Service<\/h4>\n\n\n\n<p>Once you\u2019ve saved the config file, apply changes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo systemctl restart sshd<\/code><\/pre>\n\n\n\n<p>Your configuration is now active.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Allow SSH Through the Firewall<\/h4>\n\n\n\n<p>If you&#8217;re using a firewall (like <code>ufw<\/code> or <code>firewalld<\/code>), don\u2019t forget to allow SSH traffic.<\/p>\n\n\n\n<p>For UFW:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo ufw allow ssh<\/code><\/pre>\n\n\n\n<p>Or for a custom port:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo ufw allow 2222\/tcp<\/code><\/pre>\n\n\n\n<p>For Firewalld:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo firewall-cmd --permanent --add-service=ssh<br>sudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Use SSH Keys for Better Security<\/h4>\n\n\n\n<p>Instead of passwords, it\u2019s better to allow access using <strong>SSH key authentication<\/strong>.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Generate an SSH key on the client: bashCopyEdit<code>ssh-keygen<\/code><\/li>\n\n\n\n<li>Copy the key to the server: bashCopyEdit<code>ssh-copy-id username@server_ip<\/code><\/li>\n<\/ol>\n\n\n\n<p>This prevents brute-force password attacks.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to Deny SSH Access in Linux?<\/h2>\n\n\n\n<p>Sometimes, you may want to <strong>block specific users or groups<\/strong> from accessing your server remotely \u2014 for example, to lock down a former employee or protect the <code>root<\/code> account.<\/p>\n\n\n\n<p>Here\u2019s how to do it efficiently and securely.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Deny Users via sshd_config<\/h3>\n\n\n\n<p>Edit the same SSH config file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n<p>Add the following directive at the end:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>DenyUsers username1 username2<\/code><\/pre>\n\n\n\n<p>You can also block entire groups:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>DenyGroups groupname<\/code><\/pre>\n\n\n\n<p>Save and restart SSH:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo systemctl restart sshd<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Disable Root Login via SSH<\/h4>\n\n\n\n<p>It&#8217;s a <strong>security best practice<\/strong> to block root access:<\/p>\n\n\n\n<p>Inside <code>\/etc\/ssh\/sshd_config<\/code>, set:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>PermitRootLogin no<\/code><\/pre>\n\n\n\n<p>Restart the SSH service again.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Restrict SSH by IP Address<\/h4>\n\n\n\n<p>Want to deny SSH access from certain IPs? Use TCP wrappers or firewall rules.<\/p>\n\n\n\n<p>Edit <code>\/etc\/hosts.deny<\/code> and add:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sshd: 192.168.1.100<\/code><\/pre>\n\n\n\n<p>Then edit <code>\/etc\/hosts.allow<\/code> to whitelist trusted IPs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sshd: 192.168.1.50<\/code><\/pre>\n\n\n\n<p>Or with UFW:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo ufw deny from 192.168.1.100 to any port 22<\/code><\/pre>\n\n\n\n<p>This method gives you IP-level control over SSH access.<\/p>\n\n\n\n<p>By now, you\u2019ve seen how <a href=\"https:\/\/qloudhost.com\/blog\/complete-website-migration-checklist\/\">easily you can control who gets SSH access<\/a> and who doesn\u2019t \u2014 whether you\u2019re opening the gates for trusted users or locking down your server from unwanted logins. But remember, <strong>a secure configuration starts with a reliable hosting provider<\/strong>.<\/p>\n\n\n\n<p>If you\u2019re looking for a powerful, developer-friendly, and secure environment to manage your Linux servers, <strong><a href=\"https:\/\/qloudhost.com\/\" data-type=\"link\" data-id=\"https:\/\/qloudhost.com\/\">QloudHost<\/a><\/strong> is a name you can trust. With full root access, <strong><a href=\"https:\/\/qloudhost.com\/blog\/how-to-improve-website-performance\/\">high-performance VPS<\/a><\/strong> and <strong>dedicated servers<\/strong>, and <strong>100% DMCA ignored<\/strong> privacy \u2014 QloudHost gives you the freedom and control you need, backed by rock-solid infrastructure. Ready to manage your servers the right way?<\/p>\n\n\n\n<p>Host smart. Host with QloudHost.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs &#8211; How to Allow or Deny SSH Access In Linux<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. How do I know if SSH is enabled on my Linux server?<\/strong><\/h4>\n\n\n\n<p>To check whether the SSH service is running on your Linux system, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo systemctl status sshd<\/code><\/pre>\n\n\n\n<p>If the service is active, you\u2019ll see a status like <strong>\u201cactive (running)\u201d<\/strong> in green. Alternatively, you can use:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>ss -tulpn | grep ssh<\/code><\/pre>\n\n\n\n<p>This checks if the SSH daemon is listening on the expected port (usually port 22). If it\u2019s not running, you can enable it using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo systemctl start sshd<br>sudo systemctl enable sshd<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Can I allow SSH access to a group instead of individual users?<\/strong><\/h4>\n\n\n\n<p>Yes, Linux allows you to grant SSH access to specific user groups using the <code>AllowGroups<\/code> directive in the SSH configuration file.<\/p>\n\n\n\n<p>To do this:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the SSH config file: bashCopyEdit<code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/li>\n\n\n\n<li>Add the line: bashCopyEdit<code>AllowGroups sshusers<\/code><\/li>\n<\/ol>\n\n\n\n<p>Make sure the users you want to grant access to are members of the <code>sshusers<\/code> group:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo usermod -aG sshusers username<\/code><\/pre>\n\n\n\n<p>Then restart SSH to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo systemctl restart sshd<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. What happens if I misconfigure sshd_config?<\/strong><\/h4>\n\n\n\n<p>A misconfigured <code>sshd_config<\/code> file can <strong>lock you out of your server<\/strong>, especially if you\u2019re connected remotely via SSH. To avoid this:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always <strong>test the configuration<\/strong> before restarting SSH: bashCopyEdit<code>sshd -t<\/code> This checks for syntax errors.<\/li>\n\n\n\n<li>Keep an <strong>open SSH session<\/strong> when making changes so you don\u2019t lose access.<\/li>\n\n\n\n<li>Consider setting a <strong>short timeout<\/strong> when restarting the SSH service, like: bashCopyEdit<code>sudo systemctl restart sshd &amp;&amp; sleep 5 &amp;&amp; echo \"Restarted\"<\/code><\/li>\n<\/ul>\n\n\n\n<p>Always double-check user and port configurations before applying changes.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Is it safe to use SSH with just a password?<\/strong><\/h4>\n\n\n\n<p>Using SSH with passwords is functional, but not the most secure option. Password authentication is <strong>vulnerable to brute-force attacks<\/strong>, especially if the password is weak or reused.<\/p>\n\n\n\n<p>The recommended best practice is to use <strong>SSH key-based authentication<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It eliminates the risk of password guessing.<\/li>\n\n\n\n<li>You can disable password login entirely using: bashCopyEdit<code>PasswordAuthentication no<\/code><\/li>\n<\/ul>\n\n\n\n<p>With key-based authentication, only clients with the correct private key can access your server \u2014 making it far more secure.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. How to change the default SSH port?<\/strong><\/h4>\n\n\n\n<p>Changing the default SSH port (22) can help reduce unauthorized login attempts and automated attacks.<\/p>\n\n\n\n<p>Here\u2019s how to do it:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the SSH configuration file: bashCopyEdit<code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/li>\n\n\n\n<li>Locate or add the <code>Port<\/code> directive and set a new port (e.g., 2222): bashCopyEdit<code>Port 2222<\/code><\/li>\n\n\n\n<li>Save the file and restart SSH: bashCopyEdit<code>sudo systemctl restart sshd<\/code><\/li>\n\n\n\n<li>Update your firewall rules to allow the new port: bashCopyEdit<code>sudo ufw allow 2222\/tcp<\/code><\/li>\n\n\n\n<li>Connect using: bashCopyEdit<code>ssh -p 2222 user@your_server_ip<\/code><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. How can I check SSH login attempts?<\/strong><\/h4>\n\n\n\n<p>To monitor SSH login attempts, you can view authentication logs. These logs provide detailed information about successful and failed logins.<\/p>\n\n\n\n<p>On most systems:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo cat \/var\/log\/auth.log | grep sshd<\/code><\/pre>\n\n\n\n<p>Or for systems using <code>journalctl<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo journalctl -u sshd<\/code><\/pre>\n\n\n\n<p>To see failed login attempts specifically:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo grep \"Failed password\" \/var\/log\/auth.log<\/code><\/pre>\n\n\n\n<p>This helps you detect potential unauthorized access attempts or brute-force attacks.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">7. What is the correct permission for SSH?<\/h4>\n\n\n\n<p>The correct permission for your SSH private key file (like <code>id_rsa<\/code>) should be <strong>600<\/strong> (<code>chmod 600 filename<\/code>) so only the owner can read and write it.<br>The <code>.ssh<\/code> directory itself should have permission <strong>700<\/strong> to restrict access to your user only.<br>For the <code>authorized_keys<\/code> file, the recommended permission is also <strong>600<\/strong> to maintain secure SSH access.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>8. Can I block SSH access temporarily for maintenance?<\/strong><\/h4>\n\n\n\n<p>Yes, you can temporarily disable SSH access for maintenance, but <strong>proceed with caution<\/strong>, especially if you rely on remote access.<\/p>\n\n\n\n<p>Here\u2019s how:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To <strong>stop the SSH service<\/strong>: bashCopyEdit<code>sudo systemctl stop sshd<\/code><\/li>\n\n\n\n<li>To <strong>block SSH via firewall<\/strong> (temporarily): bashCopyEdit<code>sudo ufw deny ssh<\/code><\/li>\n<\/ul>\n\n\n\n<p>Be sure to have <strong>local console access<\/strong> or another way to reconnect in case you need to reverse the changes. Once maintenance is complete, re-enable SSH:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo systemctl start sshd<\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bash<br><code>sudo ufw allow ssh<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion &#8211; How to Allow or Deny SSH Access In Linux<\/h2>\n\n\n\n<p>SSH is a powerful and essential tool \u2014 but without proper access control, it can also be a security risk. In this article, we walked you through <strong>how to allow or deny SSH access in Linux<\/strong>, from editing configuration files to setting user permissions and managing firewall rules.<\/p>\n\n\n\n<p>Whether you\u2019re an admin hardening your server or a dev setting up secure access \u2014 these best practices will help keep your Linux system safe, stable, and accessible only to the right people.<\/p>\n\n\n\n<p>Stay secure. Stay in control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever worried someone might access your Linux server without permission? SSH (Secure Shell) is the lifeline&#8230;<\/p>\n","protected":false},"author":3,"featured_media":5256,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[47],"tags":[690,689],"class_list":["post-5253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledgebase","tag-allow-or-deny-ssh-access-in-linux","tag-how-to-allow-or-deny-ssh-access-in-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/posts\/5253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/comments?post=5253"}],"version-history":[{"count":7,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/posts\/5253\/revisions"}],"predecessor-version":[{"id":10049,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/posts\/5253\/revisions\/10049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/media\/5256"}],"wp:attachment":[{"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/media?parent=5253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/categories?post=5253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qloudhost.com\/blog\/wp-json\/wp\/v2\/tags?post=5253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}