Here’s how to restore or set the Bash prompt on RHEL systems.
echo "PS1='\u@\h \w]\$'" >> ~/.bashrc source ~/.bashrc |
cloud engineer
Here’s how to restore or set the Bash prompt on RHEL systems.
echo "PS1='\u@\h \w]\$'" >> ~/.bashrc source ~/.bashrc |
echo "PS1='\u@\h \w]\$'" >> ~/.bashrc source ~/.bashrc
How to reset password of a GCP Compute Engine running on Windows OS.
gcloud compute reset-windows-password servername \ --zone us-central1-a \ --project your-project-id |
gcloud compute reset-windows-password servername \ --zone us-central1-a \ --project your-project-id
Output
This command creates an account and sets an initial password for the user [firstname_lastname] if the account does not already exist. If the account already exists, resetting the password can cause the LOSS OF ENCRYPTED DATA secured with the current password, including files and stored passwords. For more information, see: https://cloud.google.com/compute/docs/operating-systems/windows#reset Would you like to set or reset the password for [firstname_lastname] (Y/n)? y Resetting and retrieving password for [firstname_lastname] on [servername] Updated [https://www.googleapis.com/compute/v1/projects/your-project-id/zones/us-central1-a/instances/servername]. WARNING: Instance [servername] does not appear to have an external IP address, so it will not be able to accept external connections. To add an external IP address to the instance, use gcloud compute instances add-access-config. password: xxxxxxxxxxxxxxx username: firstname_lastname |
This command creates an account and sets an initial password for the user [firstname_lastname] if the account does not already exist. If the account already exists, resetting the password can cause the LOSS OF ENCRYPTED DATA secured with the current password, including files and stored passwords. For more information, see: https://cloud.google.com/compute/docs/operating-systems/windows#reset Would you like to set or reset the password for [firstname_lastname] (Y/n)? y Resetting and retrieving password for [firstname_lastname] on [servername] Updated [https://www.googleapis.com/compute/v1/projects/your-project-id/zones/us-central1-a/instances/servername]. WARNING: Instance [servername] does not appear to have an external IP address, so it will not be able to accept external connections. To add an external IP address to the instance, use gcloud compute instances add-access-config. password: xxxxxxxxxxxxxxx username: firstname_lastname
If you find yourself using a named profile for every awscli command, you can set it temporarily.
Listing a bucket with a named profile.
aws s3 ls --profile=yourprofile |
aws s3 ls --profile=yourprofile
If you set AWS_PROFILE, you can then list a bucket without a named profile.
export AWS_PROFILE=yourprofile aws s3 ls |
export AWS_PROFILE=yourprofile aws s3 ls
After you are done, you can reset it back to default.
export AWS_PROFILE=default |
export AWS_PROFILE=default
It’s recommended to set the clock to UTC. In rare occasions, local time may be needed.
Here’s how to set your server’s timezone permanently.
Check the date first.
date |
date
Backup localtime. Set it to US Eastern Time.
mv /etc/localtime /etc/localtime.backup ln -s /usr/share/zoneinfo/America/New_York /etc/localtime |
mv /etc/localtime /etc/localtime.backup ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
Backup clock. Set it to US Eastern Time.
cp -p /etc/sysconfig/clock /etc/sysconfig/clock.backup > /etc/sysconfig/clock echo ZONE=\"America/New_York\" > /etc/sysconfig/clock |
cp -p /etc/sysconfig/clock /etc/sysconfig/clock.backup > /etc/sysconfig/clock echo ZONE=\"America/New_York\" > /etc/sysconfig/clock
Run the date again to validate.
date |
date
Here’s a script that scans all EFS systems in several AWS accounts and regions and randomly assigns backup tags to EFS systems that are missing backup tags. This is assuming EFS is using AWS Backup service using tags to apply backup policies. If there are no backup tags, an EFS gets assigned a randomly picked backup policy.
#!/bin/bash # log file output="test.log" tmpfil="temp.txt" # empty file > $output # set random array arr[0]="efs-0000" arr[1]="efs-0400" arr[2]="efs-0800" arr[3]="efs-1200" arr[4]="efs-1600" arr[5]="efs-2000" rand=$[ $RANDOM %6 ] backup=${arr[$rand]} # set accounts and regions declare -a account=("default" "one" "two" "three" "four" "five") declare -a region=("us-east-1" "us-east-2" "us-west-1" "us-west-2") for i in "${account[@]}"; do echo "===================" >> $output echo $i >> $output echo "===================" >> $output for j in "${region[@]}"; do echo $j >> $output aws efs describe-file-systems \ --query "FileSystems[*].[FileSystemId,Tags[?Key=='aws-backup']|[0].Value]" \ --profile $i \ --region $j \ --output text > $tmpfil while read -r id tag; do if [[ $tag == "" ]]; then aws efs tag-resource \ --resource-id $id \ --tags Key="aws-backup",Value=${arr[$rand]} \ --profile $i \ --region $j >> $output echo "Added backup tag $backup to $id" >> $output elif [[ $tag == "no-backup" ]]; then echo "Backup tag is already set to no-backup on $id." >> $output else echo "No backup tag changes applied to $id." >> $output fi done < $tmpfil done done rm $tmpfil |
#!/bin/bash # log file output="test.log" tmpfil="temp.txt" # empty file > $output # set random array arr[0]="efs-0000" arr[1]="efs-0400" arr[2]="efs-0800" arr[3]="efs-1200" arr[4]="efs-1600" arr[5]="efs-2000" rand=$[ $RANDOM %6 ] backup=${arr[$rand]} # set accounts and regions declare -a account=("default" "one" "two" "three" "four" "five") declare -a region=("us-east-1" "us-east-2" "us-west-1" "us-west-2") for i in "${account[@]}"; do echo "===================" >> $output echo $i >> $output echo "===================" >> $output for j in "${region[@]}"; do echo $j >> $output aws efs describe-file-systems \ --query "FileSystems[*].[FileSystemId,Tags[?Key=='aws-backup']|[0].Value]" \ --profile $i \ --region $j \ --output text > $tmpfil while read -r id tag; do if [[ $tag == "" ]]; then aws efs tag-resource \ --resource-id $id \ --tags Key="aws-backup",Value=${arr[$rand]} \ --profile $i \ --region $j >> $output echo "Added backup tag $backup to $id" >> $output elif [[ $tag == "no-backup" ]]; then echo "Backup tag is already set to no-backup on $id." >> $output else echo "No backup tag changes applied to $id." >> $output fi done < $tmpfil done done rm $tmpfil
Here’s how to set the instance scope in GCP. Stop the server.
gcloud compute instances stop server-name |
gcloud compute instances stop server-name
Default scopes.
gcloud beta compute instances set-scopes server-name \ --service-account=your-service-account@gserviceaccount.com \ --scopes=default \ --project your-project-id \ --zone=us-central1-a |
gcloud beta compute instances set-scopes server-name \ --service-account=your-service-account@gserviceaccount.com \ --scopes=default \ --project your-project-id \ --zone=us-central1-a
Change scopes by adding storage-rw to default.
gcloud alpha compute instances set-scopes servername \ --service-account=your-service-account@gserviceaccount.com \ --scopes=default,storage-rw \ --project your-project-id \ --zone=us-central1-c |
gcloud alpha compute instances set-scopes servername \ --service-account=your-service-account@gserviceaccount.com \ --scopes=default,storage-rw \ --project your-project-id \ --zone=us-central1-c
Start the server.
gcloud compute instances start server-name |
gcloud compute instances start server-name
Possible scope values.
Ubuntu and Linux Mint use nano as their default editor. You’ll see it if you try to edit crontab or visudo. Now, there’s nothing wrong with nano, but I prefer using vim instead. Here’s how to change the default editor.
sudo update-alternatives --config editor |
sudo update-alternatives --config editor
You’ll be prompted to change the default editor.
There are 4 choices for the alternative editor (providing /usr/bin/editor). Selection Path Priority Status ------------------------------------------------------------ 0 /bin/nano 40 auto mode 1 /bin/ed -100 manual mode 2 /bin/nano 40 manual mode * 3 /usr/bin/vim.basic 30 manual mode 4 /usr/bin/vim.tiny 15 manual mode Press <enter> to keep the current choice[*], or type selection number: |
There are 4 choices for the alternative editor (providing /usr/bin/editor). Selection Path Priority Status ------------------------------------------------------------ 0 /bin/nano 40 auto mode 1 /bin/ed -100 manual mode 2 /bin/nano 40 manual mode * 3 /usr/bin/vim.basic 30 manual mode 4 /usr/bin/vim.tiny 15 manual mode Press <enter> to keep the current choice[*], or type selection number:
Type 3 to choose vim basic.
Here’s another way of setting your server’s timezone. See all the options under North America.
timedatectl list-timezones | grep -i America |
timedatectl list-timezones | grep -i America
Set timezone.
timedatectl set-timezone America/New_York |
timedatectl set-timezone America/New_York
To check.
date |
date
Restart cron if needed.
systemctl restart cron.service |
systemctl restart cron.service