<?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>Forem: Ali Zand</title>
    <description>The latest articles on Forem by Ali Zand (@alizand1992).</description>
    <link>https://forem.com/alizand1992</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%2F131101%2Ff00b7738-d45a-44b6-9277-bfb91a852a12.png</url>
      <title>Forem: Ali Zand</title>
      <link>https://forem.com/alizand1992</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alizand1992"/>
    <language>en</language>
    <item>
      <title>Setting Up Google Auth With React, Rails API, and Devise</title>
      <dc:creator>Ali Zand</dc:creator>
      <pubDate>Sun, 10 Mar 2024 03:51:15 +0000</pubDate>
      <link>https://forem.com/alizand1992/setting-up-google-auth-with-react-rails-api-and-devise-2j2m</link>
      <guid>https://forem.com/alizand1992/setting-up-google-auth-with-react-rails-api-and-devise-2j2m</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;When I was trying to setup "Continue with Google" functionality for my personal project I encountered numerous articles and tutorials on how to get it done. Tutorials I found covered setup for a monolith Rails setup or a frontend React setup; however none addressed setup for a Rails API with devise for auth and a React frontend. This is the same project that prompted &lt;a href="https://dev.to/alizand1992/setting-up-user-auth-with-react-and-rails-minus-the-jwt-headache-39d"&gt;this tutorial&lt;/a&gt; so I will skip the initial setup and focus on the Google OAuth.&lt;/p&gt;

&lt;p&gt;For this tutorial we will be taking components from many other articles and tutorials and combining them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;The solution that I opted for is to have Rails take care of everything instead of having the React frontend receive the OAuth token and pass it back to Rails. So all of the auth setup is done on the backend and the frontend only sends the user to a backend url.&lt;/p&gt;

&lt;p&gt;Please note that in my other tutorial I used a non-api setup for Rails but this is also achievable with the API setup. That's the setup I am going to be using for this tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Set everything up as described &lt;a href="https://dev.to/alizand1992/setting-up-user-auth-with-react-and-rails-minus-the-jwt-headache-39d"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Add SSL to all components (Google requires this)
I have my own domain that I used for the server name in the nginx config. To get certs for the &lt;code&gt;dev.my.amazing.website.com&lt;/code&gt; I created a temporary &lt;code&gt;nginx&lt;/code&gt; server on my staging server with that server name and had &lt;a href="https://letsencrypt.org/getting-started/"&gt;letsencrypt&lt;/a&gt; create the certs then used &lt;a href="https://man7.org/linux/man-pages/man1/scp.1.html"&gt;scp&lt;/a&gt; to copy them over to my local environment. You can also create a wildcard cert if you'd like so you can use it for all environments. Please note that Google does NOT allow self-signed certs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nginx
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
  listen 80;
  listen [::]:80;

  server_name dev.my.amazing.website.com;
  return 301 https://dev.my.amazing.website.com;$request_uri;
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;

  ssl_certificate    /etc/nginx/certs/fullchain.pem;
  ssl_certificate_key    /etc/nginx/certs/privkey.pem;

  server_name dev.my.amazing.website.com;

  location / {
    proxy_pass https://web:3000;
  }

  location /api {
    proxy_pass https://app;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Please Note:&lt;/strong&gt; the use of &lt;code&gt;web&lt;/code&gt; and &lt;code&gt;app&lt;/code&gt;, This is because I am using docker to run my services and that's their name in my compose file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rails
&lt;/h3&gt;

&lt;p&gt;To add SSL to the Rails backend we need to update the &lt;code&gt;config/puma.rb&lt;/code&gt; to contain the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;key = "#{File.join('config', 'certs', 'privkey.pem')}"
crt = "#{File.join('config', 'certs', 'fullchain.pem')}"
ssl_bind '0.0.0.0', 443, {
  key: key,
  cert: crt,
  verify_mode: 'none'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  React
&lt;/h3&gt;

&lt;p&gt;React requires three environment variables to be set in order to enable SSL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTPS=true
SSL_CERT_FILE=path/to/fullchain.pem
SSL_KEY_FILE=path/to/privkey.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Things to note:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;My setup is using docker so the cert files are mounted volumes.&lt;/li&gt;
&lt;li&gt;Let's encrypt creates symlinks to actual files and docker does not mount symlinks if only the directory is setup as the volume so you'd need to add each symlink as a volume in your compose file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;volumes:
  - "/host/path/to/fullchain.pem:/path/to/fullchain.pem"
  - "/host/path/to/privkey.pem:/path/to/privkey.pem"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install required Gems
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Gemfile
gem "omniauth"
gem "omniauth-linkedin-oauth2"
gem 'omniauth-google-oauth2'
gem 'omniauth-rails_csrf_protection', '~&amp;gt; 1.0' # https://github.com/heartcombo/devise/issues/5236
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then install the gems by using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ bundle install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Route Setup
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# routes.rb
scope '/api' do
  devise_for :users,
             controllers: {
               omniauth_callbacks: 'users/omniauth_callbacks',
             }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Environment Setup
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# development.rb and all other environment files
Rails.application.configure do
.
.
.
end

OmniAuth.config.full_host = ENV['FULL_HOST']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This is required so Omniauth gem sends the correct redirect url to the provider.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Omniauth Controller
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Users::OmniauthCallbacksController &amp;lt; Devise::OmniauthCallbacksController
  def google_oauth2
    @user = User.from_google_omniauth(request.env["omniauth.auth"])
    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication
    else
      session["devise.oauth_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
      redirect_to '/path/to/frontend/failure/state'
    end
  end

  def failure
    redirect_to '/user/sign_in?error=Unknown'
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;user.rb
Add these strategies to the devise command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:omniauthable, omniauth_providers: [:google_oauth2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following functions to the user.rb file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def self.authenticate(email, password)
    user = User.find_for_authentication(email: email)
    user.try(:valid_password?, password) ? user : nil
  end

  def self.new_with_session(params, session)
    super.tap do |user|
      if session["devise.oauth_data"].present?
        provider = session["devise.oauth_data"]["provider"]
        if provider == "google_oauth2"
          if data = session["devise.oauth_data"]
            user.email = data["info"]["email"] if user.email.blank?
          end
        end
      end
    end
  end

  # first_or_create acts as both signup and signin.
  def self.from_google_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
      user.email = auth.extra.id_info.email
      user.password = Devise.friendly_token[0, 20]
    end
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the provider and uid columns to the user model
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails g migration AddProviderAndUidToUsersTable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the migration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def change
  add_column(:users, :provider, :string)
  add_column(:users, :uid, :string)
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then run the migration using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;configure devise
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# devise.rb
# Below line is needed since we are not using the monolith 
# rails and cannot send a post request using a button. I 
# tried all sorts of Ajax tricks and even a for submit and it
# rewrote the method as get. This can cause security issues. 
# If you find a solution to this Please leave a comment on 
# this tutorial.
OmniAuth.config.allowed_request_methods = %i[get post]

if Rails.env != 'test'
  if Rails.application.credentials.config.key?(:google)
    config.omniauth :google_oauth2,
                    Rails.application.credentials.dig(:google, :client_id),
                    Rails.application.credentials.dig(:google, :client_secret),
                    {}
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Making sure it the routes are setup
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails routes | grep omni 
   user_google_oauth2_omniauth_authorize GET|POST /api/users/auth/google_oauth2(.:format)                                                           users/omniauth_callbacks#passthru
    user_google_oauth2_omniauth_callback GET|POST /api/users/auth/google_oauth2/callback(.:format)                                                  users/omniauth_callbacks#google_oauth2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create App Credentials
I followed this &lt;a href="https://developers.google.com/identity/protocols/oauth2"&gt;documentation&lt;/a&gt; from google to obtain the &lt;code&gt;client_id&lt;/code&gt; and the &lt;code&gt;client_secret&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When setting up the app credentials be sure to enter the redirect URI and the JS Origin to the list. Additionally, since we are not using localhost we need to add test email addresses to the &lt;code&gt;Test users&lt;/code&gt; section of the &lt;code&gt;OAuth consent screen&lt;/code&gt;. Once the app is ready it can be published to Google for review. If the app is approved then any user can sign in/up via Google without needing to be added to this list.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the the id and the secret to your credentials file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ EDITOR=&amp;lt;your_favourite_editor&amp;gt; rails credentials:edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Please Note&lt;/strong&gt; That some editors may need the &lt;code&gt;--wait&lt;/code&gt; keyword in which case the command look more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ EDITOR="&amp;lt;your_favourite_editor&amp;gt; --wait" rails credentials:edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;add the following information to your credentials&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;google:
  client_id: &amp;lt;client_id&amp;gt;
  client_secret: &amp;lt;client_secret&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;At this point you can start all your services and if you continue to the passthrue you can successfully Continue with Google.&lt;/p&gt;

</description>
      <category>react</category>
      <category>rails</category>
      <category>oauth</category>
      <category>google</category>
    </item>
    <item>
      <title>Setting Up User Auth With React and Rails Minus The JWT Headache</title>
      <dc:creator>Ali Zand</dc:creator>
      <pubDate>Thu, 22 Dec 2022 23:53:44 +0000</pubDate>
      <link>https://forem.com/alizand1992/setting-up-user-auth-with-react-and-rails-minus-the-jwt-headache-39d</link>
      <guid>https://forem.com/alizand1992/setting-up-user-auth-with-react-and-rails-minus-the-jwt-headache-39d</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Most of the tutorials that I've encountered on setting up User Auth for React and Rails with Devise involves the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rails API&lt;/li&gt;
&lt;li&gt;Devise&lt;/li&gt;
&lt;li&gt;CORS setup for Rails&lt;/li&gt;
&lt;li&gt;Some sort of JWT library like Doorkeeper or devise-jwt&lt;/li&gt;
&lt;li&gt;Use of localStorage to store the JWT token.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The are multiple problems with the above setup. The most important of which is storage of the JWT token in localStorage. This is not a safe method as other JS would have access to localStorage and the JWT can be compromised.&lt;/p&gt;

&lt;p&gt;The second problem with this method is how much work it takes to complete the setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Turns out a secure HTTP Cookie is the most secure method of storing the user session data on the frontend. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rails (none-API)&lt;/li&gt;
&lt;li&gt;Devise&lt;/li&gt;
&lt;li&gt;nginx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Notes:&lt;/em&gt; I will not go over the initial Rails or Devise setup in this document as it is very well documented through Rails and Devise documentation.&lt;/p&gt;

&lt;p&gt;The key to this solution working is the using the same domain for the frontend and the backend.&lt;/p&gt;

&lt;h3&gt;
  
  
  Repo Setup
&lt;/h3&gt;

&lt;p&gt;React application and Rails application do not be in the same repo and React application does not be setup as part of the Rails application for this solution to work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Setup Rails and Devise following steps from their respective documentation.&lt;/li&gt;
&lt;li&gt;Setup puma to run on a different port than React either by updating &lt;code&gt;config/puma.rb&lt;/code&gt; to include
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;port ENV.fetch("PORT") { 3001 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or using the &lt;code&gt;-p&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails s -p 3001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my case I have chosen port 3001&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setup the React Application.&lt;/li&gt;
&lt;li&gt;Setup nginx:
We will use nginx as a proxy pass to redirect calls to &lt;code&gt;/&lt;/code&gt; to the React frontend and the calls to &lt;code&gt;/api&lt;/code&gt; to the Rails backend.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# /etc/nginx/sites-available/default
server {
    listen 80;
    listen [::]:80;

    server_name my.amazing.website.com;

    location / {
         proxy_pass http://127.0.0.1:3000;
    }

    location /api {
         proxy_pass http://127.0.0.1:3001;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Restart nginx to load the new configuration
&lt;code&gt;sudo service nginx reload&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Place the users routes under the &lt;code&gt;/api&lt;/code&gt; scope
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  scope '/api' do
    devise_for :users
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enable rails to respond to json requests by adding the following to the ApplicationController
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;respond_to :json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Allow Rails to accept post requests w/o providing an authenticity token by adding the following to the ApplicationController
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;skip_before_action :verify_authenticity_token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>rails</category>
      <category>devise</category>
    </item>
    <item>
      <title>Linux File Permissions</title>
      <dc:creator>Ali Zand</dc:creator>
      <pubDate>Sat, 28 Aug 2021 11:06:46 +0000</pubDate>
      <link>https://forem.com/alizand1992/linux-file-permissions-22nl</link>
      <guid>https://forem.com/alizand1992/linux-file-permissions-22nl</guid>
      <description>&lt;h1&gt;
  
  
  Basic File Permissions
&lt;/h1&gt;

&lt;p&gt;Linux systems in general break file permissions into three basic types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read&lt;/li&gt;
&lt;li&gt;Write&lt;/li&gt;
&lt;li&gt;Execute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These basic types tie into the ownership of the file. The owners are broken down into three groups as well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Owner&lt;/li&gt;
&lt;li&gt;Group&lt;/li&gt;
&lt;li&gt;Other&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These permissions and ownerships are represented as a three digit number. Each digit can have a value of 0-7 (inclusive). first digit represents owner permissions, the second digit represents group permissions, and the last digit is for others. There is a number associated with each permission where read has a value of 4, write has a value of 2, and execute has a value of 1. &lt;/p&gt;

&lt;p&gt;When we look at the binary values for these permissions it all makes sense:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read:    (4)d = (100)b
Write:   (2)d = (010)b
Execute: (1)d = (001)b
----------------------
All:     (7)d = (111)b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because of this design we can easily find/set permissions for any file in linux.&lt;/p&gt;

&lt;p&gt;For example a file that has all permissions for Owner, but no permissions for group or others will have a permission of 700.&lt;/p&gt;

&lt;h1&gt;
  
  
  Changing permissions on a file in Linux
&lt;/h1&gt;

&lt;p&gt;To change the permissions of a file we use a utility called chmod. chmod stands for Change Mode. This is a utility that is shipped with many linux distributions. Since chmod is changing permissions on a file (writing new permissions) then you need to have write access to the file that you are trying to change.&lt;/p&gt;

&lt;p&gt;so the code looks like something like this: sudo chmod 777 file_name&lt;/p&gt;

&lt;h1&gt;
  
  
  Changing ownership of a file in linux
&lt;/h1&gt;

&lt;p&gt;To change the ownership of a file we use a utility called chown which stands for change owner the syntax for this is as follows:&lt;br&gt;
sudo chown user:user_group file_name&lt;/p&gt;

&lt;p&gt;If you have any questions or there is something incorrect here please let me know and I will fix it.&lt;/p&gt;

</description>
      <category>linux</category>
    </item>
  </channel>
</rss>
