Linux TroubleShooting

sudo adduser <username>

2. List available users in Linux/Ubuntu

awk -F':' '{ print $1}' /etc/passwdor cat /etc/passwd

3. List users in sudo / super user group

grep '^sudo:.*$' /etc/group | cut -d: -f4orcat /etc/group | grep sudo

4. How to AWS instance details inside the Ubuntu instance.

# Install below mentioned module
sudo apt-get install cloud-utils
# for all details execute
ec2metadata
# it returns following attributes:
ami-id:
ami-launch-index:
ami-manifest-path:
ancestor-ami-ids:
availability-zone:
block-device-mapping:
instance-action:
instance-id:
instance-type:
local-hostname:
local-ipv4:
kernel-id:
mac:
profile:
product-codes:
public-hostname:
public-ipv4:
public-keys:
ramdisk-id:
reservation-id:
security-groups:
user-data:
# for specific details like : Instance Id
EC2_INSTANCE_ID=$(ec2metadata --instance-id)

4. Ubuntu Profiles update

sudo vim ~/.profile
sudo vim /etc/profile

Golang environment variable update.

go env -w GO111MODULE=auto

Github Private repo access

git clone https://<User>:<Token>@github.com/<User>/BranchName.git

To Change (add/remove) permissions

sudo chmod +rwx <file/directory name>

To List Users from a group in Ubuntu

# list all members of specific group in linux #
awk
-F':' '/<groupname>/{print $4}' /etc/group
# list all members of sudo group in linux #
awk -F':' '/sudo/{print $4}' /etc/group
Enter the following command to check which group a certain user belongs to:$ groups [username]

List / Start / Restart/ Stop service in Ubuntu

#List all service status
systemctl list-unit-files --type service -all
# Currently running services
sudo systemctl | grep running
# Start the service
sudo systemctl start <service-name>
# Stop the service
sudo systemctl stop <service-name>
# Restart the service
sudo systemctl restart <service-name>
# Check status of a service
sudo systemctl status <service-name>
# Configure service to start at system boot
sudo systemctl enable <service-name>
or enable and start the service at the same time
sudo systemctl enable --now <service-name>

Change ownership

sudo chown -R ubuntu:ubuntu $HOME/.kube
sudo chown -R $USER $HOME/.kube

batch : date time

set mydate=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_%time:~0,2%:%time:~3,2%:%time:~6,2%

echo %mydate%

Data disk attachment verification

sudo lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i “sd”
sudo blkid -c /dev/nul | awk -F: ‘{print $1}’ | grep -i “/dev/sd”

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SaurabhG

SaurabhG

123 Followers

I am an enthusiastic learner. Always want to challenge my last learning & keep hunting for new learning. about.me/saurabh.gangrade