Saturday, June 26, 2021

Script to Change Password for a Particular User on Remote Server

 

If you have N number of servers and you have to change password on all server for a particular user like root or any other user you can user this script .


=> Use below script and modify according to your need !


#!/bin/bash

for server in 192.168.1.50 192.168.1.51 192.168.1.53 192.168.1.55

do

echo -e "Changing password for Server: $server"

ssh root@$server 'echo "your_new_passwd" | passwd --stdin username'

done



Note : in place of username use your username and in place of
your_new_password use your new password and change ip
according to your environment.




If you want to create Samba User Click here




Thanks

Friday, June 25, 2021

How to Add Master Branch in GIT | How to Add Master Branch in AWS CodeCommit

 

1 => Take git clone from blank repo of CodeCommit or GIT .

Note: Make sure before starting this process you have done your GIT access configuration on your system.


#cd /var/www/html/ 


# git clone  (your git repo url) project

Example :
#git clone ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/project project


Cloning into 'project'...
warning: You appear to have cloned an empty repository.


2 => Now copy you project in project folder 

rsync -a Colibrism/ project/

=> verify your files 

ls project

=> Now go inside project folder 

#cd project

=> Now add all your files and folder in git add 

#git add .

=> Use git status in your bash to view all the files which are going to be staged to the first commit

#git status

On branch master


No commits yet


Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

new file:   .DS_Store

new file:   api.php

new file:   apps/.DS_Store

new file:   apps/native/.DS_Store

new file:   apps/native/ajax/.DS_Store

new file:   apps/native/ajax/ads/content.php

new file:   colibri-db.sql

new file:   index.php

new file:   nginx.conf

new file:   robots.txt

new file:   update.php

new file:   upload/.DS_Store

new file:   upload/default/avatar.png

new file:   upload/default/cover.png

new file:   web.config



3 => Set your mail id  and name for your identity

 
# git config --global user.email "Your mail ID"

Example# git config --global user.email "nirmal@gmail.com"
 

# git config --global user.name "Your Name"

Example# git config --global user.name "Nirmal Singh" 

4 => Now commit your files in master branch



# git commit -m "Master branch data"

git commit -m "Master branch data"

[master (root-commit) 23db1fc] add first file

 15 files changed, 1471 insertions(+)

 create mode 100644 .DS_Store

 create mode 100755 api.php

 create mode 100644 apps/.DS_Store

 create mode 100644 apps/native/.DS_Store

 create mode 100644 apps/native/ajax/.DS_Store

 create mode 100644 apps/native/ajax/ads/content.php

 create mode 100755 colibri-db.sql

 create mode 100755 index.php

 create mode 100644 nginx.conf

 create mode 100755 robots.txt

 create mode 100755 update.php

 create mode 100644 upload/.DS_Store

 create mode 100755 upload/default/avatar.png

 create mode 100755 upload/default/cover.png

 create mode 100755 web.config 

5 => Now push your master  code on server


# git push origin master

Warning: Permanently added the RSA host key for IP address '52.95.19.19' to the list of known hosts.

Enumerating objects: 23, done.

Counting objects: 100% (23/23), done.

Delta compression using up to 4 threads

Compressing objects: 100% (22/22), done.

Writing objects: 100% (23/23), 17.71 KiB | 2.95 MiB/s, done.

Total 23 (delta 4), reused 0 (delta 0), pack-reused 0

To ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/project

 * [new branch]      master -> master




6 => Now verify your data in AWS CodeCommit in AWS account 








Saturday, June 19, 2021

15 Tar Command Examples for Administrator | Tar Command Examples for Administrator

 

15 Tar Command Examples in Linux


The Linux “tar” stands for tape archive, which is used by a large number of Linux system administrators to use this command for tape drives backup. The tar command used to rip a collection of files and directories into a highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.

Tar Usage and Options

  1. c – create an archive file.

  2. x – extract an archive file.

  3. v – show the progress of the archive file.

  4. f – filename of the archive file.

  5. t – viewing the content of the archive file.

  6. j – filter archive through bzip2.

  7. z – filter archive through gzip.

  8. r – append or update files or directories to the existing archive files.

  9. W – Verify an archive file.

  10. wildcards – Specify patterns in UNIX tar command.

1. Create tar Archive File

The below example command will create a tar archive file nirmal-19-06-21.tar for a directory /home/nirmal in the current working directory. See the example command in action.

# tar -cvf nirmal-19-06-21.tar /home/nirmal/

  1. c – Creates a new .tar archive file.

  2. v – Verbosely show the .tar file progress.

  3. f – Filename type of the archive file.

2. Create tar.gz Archive File

To create a compressed gzip archive file we use the option as z. For example, the below command will create a compressed MyImages-19-06-21.tar.gz file for the directory /home/MyImages. (Note: tar.gz and tgz both are similar).

# tar cvzf nirmal-19-06-21.tar.gz /home/nirmal

OR

# tar cvzf nirmal-19-06-21.tgz /home/nirmal


3. To Create tar.bz2 Archive File

# tar cvfj Php.tar.bz2 /home/php

OR

# tar cvfj Php.tar.tbz /home/php

OR 

# tar cvfj Php.tar.tb2 /home/php


4. To Untar tar Archive File

To untar or extract a tar file, just issue the following command using option x (extract). For example, the below command will untar the file html-19-06-21.tar in the present working directory. If you want to untar in a different directory then use option as -C (specified directory).

## Untar files in Current Directory ##

# tar -xvf html-19-06-21.tar


## Untar files in specified Directory ##

# tar -xvf html-19-06-21.tar -C /home/html/data/


5. To Uncompress tar.gz Archive File

To Uncompress tar.gz archive file, just run the following command. If we would like to untar in different directories, just use option -C and the directory path, as shown in the above example.

# tar -xvf image-19-06-21.tar.gz

6. To Uncompress tar.bz2 Archive File

To Uncompress the highly compressed tar.bz2 file, just use the following command. The below example command will untar all the .flv files from the archive file.

# tar -xvf nirmal-19-06-21.tar.bz2


7. To List Content of tar Archive File

To list the contents of the tar archive file, just run the following command with option t (list content). The below command will list the content of the upload.tar file.

# tar -tvf upload.tar



-rw-r--r-- nirmal/apache  1433 2011-08-15 18:51:10 package.xml

8. List Content tar.gz Archive File

Use the following command to list the content of the tar.gz file.

# tar -tvf staging.nirmal.com.tar.gz


-rw-r--r-- root/root         0 2012-08-30 04:03:57 staging.nirmal.com-access_log

-rw-r--r-- root/root       587 2012-08-29 18:35:12


9. List Content tar.bz2 Archive File

To list the content of the tar.bz2 file, issue the following command.

# tar -tvf Php.tar.bz2


drwxr-xr-x root/root         0 2012-09-15 03:06:08 /home/php/

-rw-r--r-- root/root      1751 2012-09-15 03:06:08 /home/php/index.php

-rw-r--r-- root/root      1273 2012-09-15 03:06:08 /home/php/index.html

10. Untar Single file from tar File

To extract a single file called cleanfiles.sh from cleanfiles.sh.tar use the following command.

# tar -xvf myfile.sh.tar myfile.sh

OR

# tar --extract --file=myfile.sh.tar myfile.sh

myfile.sh

11. Untar Single file from tar.gz File

To extract a single file nirmalbackup.xml from the nirmalbackup.tar.gz archive file, use the command as follows.

# tar -zxvf nirmalbackup.tar.gz nirmalbackup.xml

OR

# tar --extract --file=nirmalbackup.tar.gz nirmalbackup.xml


nirmalbackup.xml

12. Untar Single file from tar.bz2 File

To extract a single file called index.php from the file Phpfiles-org.tar.bz2 use the following option.

# tar -jxvf myfile.tar.bz2 home/php/index.php

OR

# tar --extract --file=myfile.tar.bz2 /home/php/index.php


/home/php/index.php

13. Untar Multiple files from tar, tar.gz, and tar.bz2 File

To extract or untar multiple files from the tar, tar.gz, and tar.bz2 archive file. For example, the below command will extract “file 1” “file 2” from the archive files.

# tar -xvf nirmal-19-06-21.tar "file1" "file2


# tar -zxvf myfile-19-06-21.tar.gz "file1" "file2


# tar -jxvf myfile.tar.bz2 "file1" "file2"

14. Extract Group of Files using Wildcard

To extract a group of files we use wildcard-based extracting. For example, to extract a group of all files whose pattern begins with .php from a tar, tar.gz, and tar.bz2 archive file.

# tar -xvf Php.tar --wildcards '*.php'


# tar -zxvf Php.tar.gz --wildcards '*.php'


# tar -jxvf Php.tar.bz2 --wildcards '*.php'



/home/php/rss.php

/home/php/index.php

/home/php/video.php

15. To Add Files or Directories to tar Archive File

To add files or directories to the existing tar archive files we use the option r (append). For example, we add file xyz.txt and directory php to the existing nirmal-19-06-21.tar archive file.

# tar -rvf nirmal-19-06-21.tar xyz.txt


# tar -rvf nirmal-19-06-21.tar php


drwxr-xr-x root/root         0 2012-09-15 02:24:21 home/nirmal/


-rw-r--r-- root/root  21063680 2012-09-15 02:24:21 home/nirmal/nirmal-19-06-21.tar




Thursday, June 17, 2021

Linux YUM Command Examples | Mostly usable Yum command in Linux

 

1. To Install a Package usingYUM

# yum install packagename

or 

#yum -y install packagename


2. Removing a Package using YUM

# yum remove packagename 

or 

#yum -y remove packagename 

3. Updating a Package using YUM

# yum update packagename 

or 

# yum -y update packagename


4. To List a Package using YUM


# yum list packagename 

5. To Search for a Package using YUM

#yum search packagename 


#yum search all  "web server"

6. To Get Information of a Package using YUM


# yum info packagename

7. To List all Available Packages using YUM

# yum list 

8. To List all Installed Packages using YUM


#yum list installed 

9. To check package name from any system file


yum provides function is used to find which package name belong to a specific file , if you want to know which package is responsible for  /etc/passwd you can run it.

#yum provides  filename

Example: #yum provides  /etc/passwd


10. To check Available Updates using Yum

By running check-update you can find how many of installed packages on your system have updates available.

#yum check-update 

11. Make Your  System up to date using Yum

This will update your system also update your configured repo data 

# yum update 

# yum update --security 

12. For Checking all available Group Packages list

This command will show you all the group list available available in yum 

#yum grouplist 


13. To Install a Group Packages using yum 

#yum groupinstall  'group package name'


14. To Update a Group Packages using yum

To update any existing installed group packages, just run the following command as shown below.

#yum groupupdate 'group package name'

like 
# yum groupupdate 'MySql Database'

15. To Remove a Group Packages using yum

This command will remove all packages related to given group. 

#you groupremove 'group package name'


16. To Check all Enabled Yum Repositories list

To list all enabled Yum repositories in your system, use following option.

#yum repolist 


16. To Check all the Enabled and Disabled Yum Repositories list

The following command will display all enabled and disabled yum repositories on the system.

# yum repolist all 


17. To Install a Package from Specific Repository

To install a particular package from a specific enabled or disabled repository, you must use –enablerepo option in your yum command. 

# yum --enablerepo=epel install httpd


18. To Check Interactive Yum Shell

Yum utility provides a custom shell where you can execute multiple commands.

# yum shell 


19. To Clean Yum Cache

This command will clean all the repo metadata and the temp downloaded packages.

# yum clean all 


20. To check History of Yum

To view all the past history of yum command like we use history command.

# yum history 


# yum history list all 



21. To undo of Yum 

To undo from history of yum command we can use below command to revert installation.

# yum history undo  "historyID" 

like 

# yum history undo  10 



22. To redo of Yum

To redo a yum install, as before, take note of the transaction ID, and run it. For instance to redo the install with ID 10, run the the following command.

# yum history redo  "historyID" 

# yum history redo  10 




23. To install local RPM  from Yum command 


# yum localinstall package.rpm 






Thanks 





Mastering Cron Jobs in Linux: A Comprehensive Guide with Examples

Introduction: Cron jobs are an indispensable tool in the world of system administration and automation. They allow users to schedule tasks t...