Git and Linux SSH Script - TrippCC/Sys-265 GitHub Wiki

Install git: sudo apt update

apt install git

git --version

Clone your Repo: git clone https://github.com/username/nameofRepo

create new dir: cd nameofRepo/ mkdir /SYS265 cd /SYS265 mkdir /docker cd /docker

Copy 50-cloud/yaml cloud.cfg docker-compose.yml and hosts to the directory

echo "docker01 configuration" >> README.md git add git status git config user.email youremail git config user.name yourname git commit -m "added a readme" git push

check the repo on a browser to see if it worked

Recovering files that were deleted locally:

cat READMe.md rm README.md git checkout . cat README.md

install git on mgmt01: https://git-scm.com/download/win

open it and cd Desktop/

clone the same repo as you did before

mkdir nameofRepo/SYS265/mgmt01 cd " / " / "

echo hostname >> README.md

cat README.md

Check git on browser to see if it worked

go back on docker: git status git pull

Install git on web01 cd tech-journal-private/SYS265 mkdir -p linux/{public-keys,centos7} cd linux/ ls nano centos7/secure-ssh.sh #secure-ssh.sh #author username #creates a new ssh user $1 parameter #adds a public key from the local repo or curled from the remote repo #removes roots ability to ssh in echo "ALL YOUR CODE GOES HERE"

push the changes as you have previously.

Creating RSA keypair: ssh-keygen -t rsa -C "name" give it no passphrase

cd /root/tech-journal-private/SYS265/linux/public-keys then: cp ~/.ssh/id_rsa.pub .

then add commit and push

switch to docker and make sure you pull from the repo

Manually creating a user that can login using RSA (substituting $1 for a username)

useradd -m -d /home/$1 -s /bin/bash $1 mkdir /home/$1/.ssh cp SYS265/linux/public-keys/id_rsa.pub /home/$1/.ssh/authorized_keys chmod 700 /home/$1/.ssh chmod 600 /home/$1/.ssh/authorized_keys chown -R $1:$1 /home/$1/.ssh

now go back on to web01 and use "ssh nameofuser@docker-mason" you should be able to login without a password

Next step is to modify the secure.ssh-sh script that you created earlier

cd tech-journal-private/SYS265/linux/centos7 vi secure-ssh.sh

enter: useradd -m -d /home/$1 -s /bin/bash $1 mkdir /home/$1/.ssh cp /root/tech-journal-private/SYS265/linux/public-keys/id_rsa.pub /home/$1/.ssh/authorized_keys chmod 700 /home/$1/.ssh chmod 600 /home/$1/.ssh/authorized_keys chown -R $1:$1 /home/$1/.ssh

the $1 is automatically linked with the parameter that is passed to the script after executing it for example ./secure-ssh.sh bob bob would be passed it to the script as the variable $1 so wherever in the script $1 appears bob will replace it when the script is ran. note: to execute a script "./" must be placed in front of the script you wish to execute.