How to restart the gnome-shell if it glitches or slows down

  1. Alt+F2
  2. Type r
  3. Press Enter
  4. There you go!
Posted in Linux | Tagged , | Leave a comment

Testing the new WordPress Mobile Editor

So far so good!

Posted in Uncategorized | Leave a comment

How to call GitHub REST API from Ubuntu

In brief, I needed to get a list of the members currently in my organization at GitHub.

There are multiple ways to do so, including:

  1. Direct calls to the API from curl
    sudo apt install curl
  2. Python using PyGitHub
    pip install pygithub
  3. Ruby using octokit
    gem install octokit

I tried all 3 and all work in a wonderful way, but I had to choose one eventually

For the simple task I needed of getting members of my GitHub organization, I just used the first method above, using the following call:

curl 'https://api.github.com/orgs/my_organization/members?page=3&per_page=100' -u "myusername:mypassword" >> myoutput.json

Another example for getting a list of the outside collaborators in my organization:

curl 'https://api.github.com/orgs/my_organization/members?page=3&per_page=100' -u "myusername:mypassword" >> myoutput.json

Where:

per_page=100: controls how many records appear per page (pagination), the maximum I could get is 100, so I had to get 2 pages in total.

page=3: The page number in case you have more than 100 records

-u: To add your GitHub username and password, in case the information you request needs authentication

Note: To convert the json to csv, I just went to https://json-csv.com/ and it did a pretty good job for me.

Enjoy!

Some Updates:

I did the conversion from json to csv also from Python, since the website tried forcing me to upgrade:

import pandas as pd
df = pd.read_json (r'/home/file1.json')
export_csv = df.to_csv (r'/home/file1.csv')
df = pd.read_json (r'/home/file2.json') #had to get the GitHub API output in 2 times
export_csv = df.to_csv (r'/home/file1.csv', mode='a', header=False) #To append the second file without the header

Sources:

  1. GitHub API V3 Documentation
  2. octokit Documentation
  3. PyGitHub Documentation
  4. Many articles on StackOverflow and ServerFault
Posted in Ubuntu, Uncategorized | Tagged , , , , , , , , , , | 1 Comment

A nice way to show progress when copying files

The cp command is not really good with that, there are some ways to do it, but unnecessarily complicated.

The best option is to use rsync instead:

rsync --progress source destination

It will show you something like this:

3885367296 0% 38.37MB/s 13:02:45

Where the first column is the number of copied bytes, the second one is the percentage of completion, the third is the copy speed and the last is the remaining time.

Source: https://unix.stackexchange.com/questions/65077/is-it-possible-to-see-cp-speed-and-percent-copied

Posted in Linux, Uncategorized | Tagged , , | Leave a comment

Force PKI and Password authentication simultaneously on Ubuntu

I use AD authentication in my environment (for password-based authentication)

Current Scenario

  1. A valid AD user logs in to the Ubuntu Linux server via SSH
  2. That user adds his public key to ~/.ssh/authorized_keys for passwordless login
  3. I disable/lock/delete the AD user to prevent him from logging in
  4. The user was still able to login to the server, since his public key is still there!

Expected Scenario: If I disable/lock/delete a user’s AD account (or his AD password expires), he shouldn’t be able to login to any server with his AD account, even if his public key is installed there.

To allow this, you just need to add this to /etc/ssh/sshd_config:

AuthenticationMethods "publickey,password" "publickey,keyboard-interactive"

This will allow you to login ONLY if you have your public key installed on the server AND enter your AD password.

I would suggest this to be in PROD systems only.

Now you have the security advantages of both PKI & AD!

Source: https://ubuntuforums.org/showthread.php?t=2155116

Posted in Linux, Ubuntu, Uncategorized | Tagged , , , , | Leave a comment