Table of Contents
This is the documentation that goes hand in hand with the video on Vagrant and Github.
We are going to learn from scratch, setting up vagrant and GitHub with SSH.
We Shall learn in depth:
1 – Checking for Virtualization support on the pc and in bios
2 – Installing the 4 essential programs
3 – Setting up Vagrant and the common commands
4 – Solving SSH time out issue – Random logging out.
5 – ctrl + c causing logging out
6 – Creating and using bash files to automate tasks
7 – Connecting to GitHub using SSH, git clone, git add, git commit, git push
8 – Installing Betty linter
9 – Adding line numbers to vim.
10 – Some debugging and much more.
1 Checking if you have virtualization Enabled
We can check if we have virtualization enabled by going to the task manager or by using command prompt.
However using command prompt is much more accurate as it tells us whether virtualization is actually enabled. Checking on task manager can show that it is enabled, but that may not be the case.
To Check if you have virtualization go to open command prompt then type this – wmic cpu get VirtualizationFirmwareEnabled
2 Install 4 programs
1 – Microsoft Visual C++ – required for oracle virtualbox – https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170
2 – VirtualBox — https://www.virtualbox.org/wiki/Downloads (windows hosts)
3 – Gitbash – better than using cmd — https://git-scm.com/download/win
4 – Vagrant – https://developer.hashicorp.com/vagrant/downloads
5 – Vagrant ubuntu/focal64 box, in case you want to install from local storage. https://app.vagrantup.com/ubuntu/boxes/focal64
3 In GIT
- right click, options, keys, ctrl+shift – to enable copying and pasting using ctrl+shift
4 Setting up vagrant with virtual box
- The vagrant box we are using is ubuntu/focal64
- in git bash, create a directory that will hold your vagrant box.
- for example, creating a vagrant folder in documents, then an ubuntu folder.
CD
into the ubuntu-focal folder
This is where all the magic happens. You will see later on how we can use bash files to be able to quickly start, login and stop our vagrant box.
The common option of adding the box, is by using this command. This will download the box and then simultaneously add it. vagrant box add ubuntu/focal64
However you can as well download it and then add it; for instance if you are on a limited data plan.vagrant box add --name ubuntu/focal64 ~/Desktop/Virtualbox/focal-server-cloudimg-amd64-vagrant.box
~/Desktop/Virtualbox/focal-server-cloudimg-amd64-vagrant.box
– replace this with the location of where you have downloaded your box.
After we have added the box, we then need to initialize it. This creates the vagrantfile. vagrant init ubuntu/focal64
Installing this plugin can sometimes sort out certain issues that would prevent you box from starting up. vagrant plugin install vagrant-vbguest
– to avoid issue with the last version of Vagrant (2.2.4 or latest)
Once initiliazed we are good to start our virtual box by doing vagrant up
command.
vagrant up
might bring problems as we experienced in the video
- first activate this – in Turn Windows features on or off
- Select Start, enter Windows features, and select Turn Windows features on or off from the list of results.
- In the Windows Features window that just opened, find Hyper-V, Virtual Machine Platform and Windows Hypervisor platform and select it.
- Select OK. You might need to restart your PC.
- In command prompt with admin priviledges run this command –
bcdedit /set hypervisorlaunchtype off
- This command disable the Hypervisor launch type this command is used to turn off the Hypervisor launch type on a Windows computer, which can be useful in certain scenarios such as when you want to run other virtualization software that may conflict with the built-in Hypervisor.
- vagrant up can disturb, especially where it hangs at this section:
default: SSH auth method: private key
. make sure you halt (you can open oracle virtualbox), and then restart your PC. Sometimes restarting solves everything.
5 After vagrant up, we login to (start) ubuntu./focal
vagrant ssh
is the command to log into our vagrant box, the ubuntu/focal64.- However using that command will will cause typing
ctrl + c
to exit ubuntu/focal - so best to use
ssh [email protected] -p2222 -i .vagrant/machines/default/virtualbox/private_key
6 Solving random logging out – time out issue
We have instances where all of a sudden after being away from your computer for a while, or when in the process of doing hard things, you notice that you have suddenly been logged out.
This can be rectified by making some changes to our ssh config file, so as to send alive packet data
- when you have already done vagrant up and you are logged in
- do
cd ~/.ssh
then open config file. if it is not there create it. ievim config
- Add the following lines to the file to set the ServerAliveInterval and ServerAliveCountMax options
- NOTE: ON THE VIDEO WE USED
ServerAliveCountMax 5L
. THIS CAN BRING ISSUES, WRITE IT WITHOUT THEL
ASServerAliveCountMax 5
Host *
ServerAliveInterval 60
ServerAliveCountMax 5
- Breakdown
ServerAliveInterval
- tells the SSH client to send a keep-alive packet (a message with no payload) to the server every 60 seconds.
- By default, SSH clients do not send any packets to the server unless there is some data to send or receive, which can cause the connection to time out due to inactivity.
- With
ServerAliveInterval
set, the SSH client will send a packet every 60 seconds, which will keep the connection active as long as the server is still responding.
ServerAliveCountMax
- sets the maximum number of keep-alive packets that can be sent without receiving a response from the server.
- If the client sends a keep-alive packet and does not receive a response from the server within a certain period (which is typically a multiple of the
ServerAliveInterval
), it assumes that the connection has been lost and tries to reconnect. - By default, the SSH client will try to reconnect indefinitely, which can be problematic if the server is no longer available or if there is some other issue preventing the connection from being established.
- With
ServerAliveCountMax
set, the client will only try to reconnect a certain number of times before giving up.
- Summary
- In general, when the client sends a keep-alive packet, the server should always respond with an acknowledgement packet, even if there is no data to send or receive.
- However, there are some cases where the server may not respond, such as if it has crashed or if the network connection has been lost.
- In these cases, the client will assume that the connection has been lost and try to reconnect.
- By setting
ServerAliveCountMax
, the client can limit the number of failed attempts to reconnect and avoid getting stuck in a loop trying to reconnect indefinitely.
- Overall, these settings help to ensure that SSH connections remain active and do not get terminated due to inactivity or other issues.
7 IMPORTANT VAGRANT COMMANDS
vagrant up
– this starts the vagrant box. Also when done for the very first time it creates the vagrant box in the oracle virtualbox.vagrant halt
– this stops the virtual box.vagrant status
– checks if virtual box is running.vagrant global-status
– lists all Vagrant environments that are currently active on your machine.
8 MAKE WORK EASIER – creating bash files
“log” – vagrant ssh
create it in the directory of where you installed your box
#!/bin/bash
ssh [email protected] -p2222 -i .vagrant/machines/default/virtualbox/private_key
“up” – vagrant up
#!/bin/bash
cd ~/Documents/Vagrant/ubuntu
vagrant up
./log
create “log” in home directory
you can also have this log file in the home directory, so that you can open more instances of ubuntu/focal
since the log file will be in the home directory, we need to include a command that changes directory to the ubuntu folder.
#!/bin/bash
cd Documents/Vagrant/ubuntu
ssh [email protected] -p2222 -i .vagrant/machines/default/virtualbox/private_key
“halt” – vagrant halt
#!/bin/bash
cd Documents/Vagrant/ubuntu
vagrant halt
9 GIT HUB – creating public and private keys
ssh-keygen -t rsa -b 4096 -C “email”
– create private and public keys
paste public key on github at ssh and gpgkeys
eval "$(ssh-agent -s)"
– starts the agent
ssh-add ~/.ssh/{key-name}
– add private key
-ssh -T [email protected]
– confirm key added
One must set their identity on GitHub
Your identity tells github who you are, so it knows when you are pushing files to github.
git config --global user.email "email-address"
– adding your GitHub email addressgit config --global user.name "username"
– adding your GitHub usernamegit config --global --list
– to check which identity has been set
Add private key to bash.rc file
so that it loads automatically every time you start a session.
- go to
.bashrc
file in home directory. ievim ~/.bashrc
- add this lines
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/{key-name}
10 Changes to Vim
Vim is a powerful text editor, but in its raw form it is lacking quite a few powerful punches.
If you were to search for a line of code, you would have a very hard time, since the editor is not numbered.
We can however mitigate this dilemma, by making a few changes with the vim editor.
In order to customise your vim
configuration, you’ll need to modify the file .vimrc
in your home directory.
This code should create the .vimrc
file with the necessary text required to do this. echo -e "set tabstop=8 shiftwidth=8\nset autoindent\nset smartindent\nset cindent\nsyntax enable\nset number\nset formatoptions+=ro" > ~/.vimrc
11 Simple Vim commands
We can easily modify our files to make sure it is in proper order and properly indented.
Here are some of the basic vim commands. Their use have been well explained in the video.
gg=G
– to autoindent%s/\s\+$//g
– remove white spaces at end%s/^[ ]\+//g
– remove white spaces at beginning.%s/^$\n//g
– remove empty lines
12 Installing Betty
GitHub site for betty documentation: https://github.com/holbertonschool/Betty
#Download script
git clone https://github.com/holbertonschool/Betty.git
#GO TO SCRIPT FOLDER - if cloned in home directory
cd Betty
#Run the script:
./install.sh
#or
sudo ./install.sh
#create new file
vim betty
#paste contents below to file
#Give execution permission
chmod a+x betty
#move betty to bin folder
mv betty /bin/
#can confirm move by
ls /bin | grep betty
#how to use betty
betty name-of-file
Code to be added in the file betty we just created. Copy exactly as so
#!/bin/bash
# Simply a wrapper script to keep you from having to use betty-style
# and betty-doc separately on every item.
# Originally by Tim Britton (@wintermanc3r), multiargument added by
# Larry Madeo (@hillmonkey)
BIN_PATH="/usr/local/bin"
BETTY_STYLE="betty-style"
BETTY_DOC="betty-doc"
if [ "$#" = "0" ]; then
echo "No arguments passed."
exit 1
fi
for argument in "$@" ; do
echo -e "\n========== $argument =========="
${BIN_PATH}/${BETTY_STYLE} "$argument"
${BIN_PATH}/${BETTY_DOC} "$argument"
done
Требитель по правонарушениям
адвокат по уголовным преступлениям [url=https://www.advokat-po-ehkonomicheskim-prestupleniyam.ru/]https://www.advokat-po-ehkonomicheskim-prestupleniyam.ru/[/url].
цены на ремонт квартир
ремонт квартир москва цены [url=ceny-na-otdelku-kvartiry.ru]ceny-na-otdelku-kvartiry.ru[/url].
Превосходные Услуги Клининга: Безопасно и Эффективно
клининговая компания москва [url=http://klining-v-moskve1.ru/]http://klining-v-moskve1.ru/[/url].
Выбирайте грузчиков с проверенным опытом и надежностью
заказать грузчиков недорого [url=http://www.pereezdpnz.ru/]http://www.pereezdpnz.ru/[/url].
Get Your Stamp Maker Now
maker stamp [url=http://gossignal.store/]http://gossignal.store/[/url].
Create Unique Stamps Quickly
make your own stamp [url=https://www.stamp-maker.ru/]https://www.stamp-maker.ru/[/url].
Stempel einfach und schnell selbst erstellen
stempel selbs gestalten [url=https://stempel-erstellen.fun]https://stempel-erstellen.fun[/url].
Цена на техническую экспертизу для строительства
строительно техническая экспертиза цена ее проведения [url=https://www.expertiza54.store]https://www.expertiza54.store[/url].