Git and Linux SSH Script Lab - Zacham17/my-tech-journal GitHub Wiki

Summary

In this lab I installed git and practiced repository management using git. I also made a script to successfully log into my docker-01 VM without a password via SSH.

Git

Installing Git

On Ubuntu Linux

  • To install git on ubuntu Linux, use the command sudo apt install git-all

On CentOS Linux

  • To install git on CentOS Linux use the command sudo yum install git
  • Set the user and email in order to commit messages will have the correct information using the following commands:
    • git config --global user.name "Your Name"
    • git config --global user.email "[email protected]"

Installing on Windows

  • To install git on windows, simply follow this link and choose the appropriate install

Cloning a Repository

  • To clone a github repository use the command git clone https://github.com/exampleuser/examplerepo, but replace the link with a repository link that you wish to download.
    • You may need to enter a username and password or access token

Managing a repository

  • After cloning a repository, there will be a repository directory in the directory that you ran git clone in.
  • You can make changes within the repository directory using basic commands.
    • You can add files, remove files, edit files, etc.
  • When you have made changes in the repository directory, you can use the git add command to select what you want to add/update in the repository.
  • After using git add use git commit -m "MESSAGEHERE" to document the change that you are making to the repository. Replace MESSAGEHERE with a note about the change you made
  • Finally, use git push to publish the changes you made on your repository and apply those changes on github.

Other Useful Git Commands

  • git status can be used to check if your repository directory is up to date with the repository on github
  • git checkout can be used to update files in a directory to match the files stored in the directory branch on github
  • git pull is used to download content from the GitHub repository and immediately update the local repository to match that content. I find this useful if I make a mistake managing the local repository.

Hardening SSH

  • For this part of the lab, I used git to manage my files that I used for the following portion of the lab

Creating an RSA Keypair

  • To generate an RSA keypair, use a command similar to the following: ssh-keygen -t rsa -C "sys265"
  • You will be asked which directory to save the key in. Hit enter to keep the default directory
  • At this point I added the public key file to my github repository using git

Using a bash shell script

The following steps will describe how to write a bash shell script that creates users for passwordless shh login

  • Create a .sh file. I used vi to do this. My file is called secure-ssh.sh. I used the command vi secure-ssh.sh
  • You then need to write in commands to automate the process of creating a user, but also make sure that when a user already exists, it can't be created again. This can be done using conditional statements and a parameter for the user
  • You can see my code HERE
    • This script creates ask for a username and creates a user and home directory using that user name.

Logging in with your created users

  • On a seperate system from the one with the .sh script, use the following command to log in without a password, ssh USER@HOST, and replace USER with a user that was created by your script and HOST with the hostname or IP address of the system that the .sh script is on
    • Ex: ssh testuser1@docker01-morris | my user is testuser1 and my host is docker01-morris