{"id":8950,"date":"2025-05-19T14:30:54","date_gmt":"2025-05-19T09:00:54","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=8950"},"modified":"2025-05-19T14:31:00","modified_gmt":"2025-05-19T09:01:00","slug":"how-do-i-create-a-read-only-user-on-an-ubuntu-server","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-do-i-create-a-read-only-user-on-an-ubuntu-server\/","title":{"rendered":"How do I create a read-only user on an Ubuntu server?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Introduction:<br><\/strong>Creating a read-only user on an Ubuntu server is useful for allowing access to specific files or directories without permitting modifications. This can enhance security by restricting user permissions to view-only access. This guide will walk you through the steps to create a read-only user on an Ubuntu server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prerequisites:<\/strong><br>1. An Ubuntu server with root or sudo access.<br><strong>Step 1:<\/strong><br>1. Access your Ubuntu server via SSH or a terminal:<br>2. Replace your_username with your current user and server_ip with your server\u2019s IP address.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>$ ssh your_username@server_ip<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2:<\/strong><br>Create a new user named readonlyuser (you can choose any name) without a home directory:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>$ adduser &#8211;no-create-home &#8211;shell \/bin\/bash readonlyuser<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3<\/strong>:<br>1. To limit the user\u2019s ability to execute commands or navigate directories, set their shell to a restricted shell like rbash:<br>2. If you don\u2019t need a restricted shell, you can keep \/bin\/bash, but rbash prevents the user from running arbitrary commands or changing directories.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>$ usermod -s \/bin\/rbash readonlyuser<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4:<\/strong><br>1. If the directory has restricted permissions (e.g., owned by root), add the user to a group with read access:<br>2. This creates a group readonlygroup, adds the user to it, sets the group as the directory\u2019s owner, and grants read permissions to the group.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>$ groupadd readonlygroup<br>$ usermod -aG readonlygroup readonlyuser<br>$ chown -R :readonlygroup \/var\/www\/html<br>$ chmod -R g+r \/var\/www\/html<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure the user cannot write or execute files in the directory:<br>   1. o-wx removes write (w) and execute (x) permissions for \u201cothers.\u201d<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>chmod -R o-wx \/var\/www\/html<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 5:<\/strong><br>1. Verify the permissions:<br>2. The output should show read-only access for \u201cothers\u201d (e.g., drwxr-xr&#8211;).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>ls -ld \/var\/www\/html<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><br><strong>Notes:<\/strong><br>1. no-create-home ensures that no home directory is created for the user.<br>2. shell \/bin\/bash sets the user\u2019s shell to \/bin\/bash.<br>3. Follow the prompts to set a password and fill in optional user details (you can leave them blank by pressing Enter).<br>4. Identify the directory you want the user to access (e.g., \/var\/www\/html for a web directory).<br>5. Grant read-only access to the directory using the following command:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>$ chmod -R o+r \/var\/www\/html<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><br><strong><br><\/strong><br><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction:Creating a read-only user on an Ubuntu server is useful for allowing access to specific files or directories without permitting [&hellip;]<\/p>\n","protected":false},"author":499,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-8950","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phns3A-2km","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/499"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8950"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8950\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}