Home > Blockchain >  Linux commands for login to Github CLI in command line
Linux commands for login to Github CLI in command line

Time:01-27

I want to login into the gh cli with parameters or flags. Im setting up a cloud-init file, with bash commands. So i can't interact manual processes: That's how it would look like if you do it manually in the console:

ubuntu@ip-172-31-54-112:~/react$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'workflow'.
? Paste your authentication token: ****************************************
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as yuuval

I tried it with this line of code which is printed:

- gh config set -h github.com git_protocol https

But it doesnt really log you into github cli. This is my Cloud-init file:

#cloud-config
keyboard:
    layout: ch
package_update: true
package_upgrade: true
packages:
    - nginx
    - git
package_reboot_if_required: true
runcmd:
  - type -p curl >/dev/null || sudo apt install curl -y
    curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
    && sudo chmod go r /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
    && sudo apt update \
    && sudo apt install gh -y
  - mkdir react
  - cd react
  - curl -o actions-runner-linux-x64-2.301.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.300.1/actions-runner-linux-x64-2.301.1.tar.gz
  - tar xzf ./actions-runner-linux-x64-2.301.1.tar.gz
  - yes "" | ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA
  - sudo ./svc.sh install
  - sudo ./svc.sh start
  - //HERE COMES THE LOGIN PART   GH WORKFLOW RUN NODE.JS.YML FILE
  - cd _work
  - cd react-deploy-aws
  - cd react-deploy-aws
  - cd /etc/nginx/sites-available
  - sudo rm default
  - 
    echo "server {listen 80 default_server;server_name _;location / {root
    /home/ubuntu/react/_work/react-deploy-aws/react-deploy-aws/build;try_files
    \$uri /index.html;}}" | sudo tee /etc/nginx/sites-available/default
  - sudo service nginx restart
  - sudo chmod  x /home
  - sudo chmod  x /home/ubuntu
  - sudo chmod  x /home/ubuntu/react
  - sudo chmod  x /home/ubuntu/react/_work
  - sudo chmod  x /home/ubuntu/react/_work/react-deploy-aws
  - sudo chmod  x /home/ubuntu/react/_work/react-deploy-aws/react-deploy-aws
  - sudo chmod  x /home/ubuntu/react/_work/react-deploy-aws/build

Does anyone know how to login via commandline and no user inputs. And if you know how to do the same with the gh workflow run command and then selecting the node.js.yaml file without user interactions needed that would be nice.

CodePudding user response:

Set an environment variable with your generated Personal Access Token e.g. PAT.

Pass it to gh auth login command with --with-token flag:

gh auth login --hostname github.com --with-token <<< $PAT

Reference:

  • Related