title: How to Authenticate to gsutil in a shell script using service account
body: <p>What is the best way to authenticate to Google Cloud Storage Bucket from a <strong>shell script</strong> (To be scheduled to run daily/hourly) using a <strong>service account</strong>?
  I have gone through the below link, but I still have some doubts regarding the login process.</p>
  <p><a href="https://stackoverflow.com/questions/12433639/how-to-use-service-accounts-with-gsutil-for-uploading-to-cs-bigquery">How to use Service Accounts with gsutil, for uploading to CS + BigQuery</a></p>
  <ol>
  <li><p>Are the below mentioned login steps a one-time process? If yes how does the login work for subsequent executions?</p>
  <p>My understanding is that the below commands writes content to the <strong>.boto</strong> file which is used in subsequent executions?
  But according to below link - it writes to a separate json file inside .config/gcloud?
  <a href="https://stackoverflow.com/questions/36966449/does-gsutil-support-creating-boto-files-with-service-account-info">Does gsutil support creating boto files with service account info?</a></p>
  <p>In such a case what is the use of a .boto file ? and why/<strong>when</strong> do we need to pass it via BOTO_PATH/BOTO_CONFIG?</p>
  <p>In gsutil (standalone), login using below steps</p>
  <pre class="lang-sh prettyprint-override"><code>gsutil config -e 
  </code></pre>
  <p>Optionally -o to output to a file other than ~/.boto</p>
  <p>gsutil as part of gcloud</p>
  <pre class="lang-sh prettyprint-override"><code>gcloud auth activate-service-account SERVICE_ACCOUNT@DOMAIN.COM --key-file=/path/key.json --project=PROJECT_ID
  </code></pre>
  </li>
  <li><p>What is the best way to prevent intervention from other scripts?</p>
  <p>For example, let us assume we have shell script S1, connecting to project P1 to upload data to Bucket B1, If another shell script say S2 is triggered at exactly the same time connecting to Project P2 uploading to Bucket B2, will it cause an issue?
  What is the best practice to avoid such issues?</p>
  </li>
  <li><p>Is it possible to limit the login to only the time of script execution?
  Say, the script is scheduled using cron to run at 10:00 AM UTC and the script completes its execution by 10:30 AM UTC.
  Is it possible to prevent any actions in the time between 10:30 till next run?
  In other words is it possible to log out and then login programatically without intervention?</p>
  </li>
  </ol>
  <p>Environment: Centos</p>