Backgrounding tasks in Linux with nohup and screen

Notes made while following along lecture in the course “Running Kali on Raspberry Pi” by Dr. Polstra on Pentest Academy

nohup

  • nohup –help (Run command, ignoring hangup signals. Basic command line direction)
  • nohup ls / -lR &
    • Runs the ls /-lR command in the background (&)
    • nohup ensures that output is written to nonhup.out and that command runs even if connection to terminal is lost
  • ls
  • logout (to simulate a loss of connection)
  • ssh -X root@<ip-add>
  • nano nohup.out

Expermiment with a script

create loopy.sh

#!/bin/bash
while true
do
echo “Computing..”
sleep 2

  • nohup ./loopy.sh &
  • tail -f nohup.out
  • nohup ./loopy.sh > loopy.out &
  • tail -f loopy.out

screen

  • which screen
  • no output imples scream not installed
  • apt update
  • apt install screen
  • screen
  • ps
  • ps -ef [pipe] grep screen
  • [CTRL A] ? — shows commands available in screen
  • [Return] to end
  • [CTRL A C] for a new screen
  • top
  • [CTRL A N] for next screen
  • vi
  • [CTRL A N] to scroll between top and vi
  • [CTRL A P] for previous
  • [CTRL A D] to detach from a screen
  • screen -r (to go back to where you started)
  • [CTRL A H] or log of sessions
    • ls -l
      • hardcopy.0
      • cat hardcopy.0
  • [CTRL A M] – to setup alterts
    • echo “starting”; sleep 10; echo “done”
    • will flash alert on the screen when there is output
  • [CTRL A X] to lock a screen
  • [CTRL A K] to kill the window

Configure wireless on Raspberry Pi

Follow instructions from previous Install kali on Pi

N.B. Connecting Pi by USB only provides power

How do I find Pi on my network?

  • open a terminal
  • ifconfig (Check what network you are on e.g. 192.168.1.123)
  • nmap 192.168.1.0/24 (to scan all hosts on the network and look for a device that just has SSH running)
  • ssh root@<ip address from step above>
  • if you haven’t changes default password from previous tutorial then use (root/toor) to authenticate session
  • change root password

Setup Wi-Fi

  • Connect a compatible adaptor (e.g. Alfa)
  • ifconfig (will show wlan0 is up but not connected to any network)
  • Look for wlan0
  • iwconfig (confirm that no networks are associated)
  • cd /etc/network
  • ls
  • nano interfaces
    • will probably show at least 2 entries
      • auto lo
      • iface lo inet loopback
      • auto eth0
      • iface eth0 inet dhcp
      • Add the following
      • auto wlan0
      • allow-hotplug wlan0
      • iface wlan0 inet dhcp (then tab)
        • wpa-ssid “yourssid”
        • wpa-psk “your password”
      • save the file
  • reboot
  • ssh root@<ip address from step above> (if IP address has changed then run nmap again)
  • ifconfig (should show wireless connection)

 

 

 

Setting up Git

https://github.com/devsecops/bootcamp/blob/master/Week-1/labs/LAB-1.md

  • [Debian] Install:
sudo apt-get update
sudo apt-get install -y git
  • [RHEL/CENTOS] Install:
sudo yum update -y
sudo yum install -y git
  • Configure:
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL"
  • Generate SSH Keys:
ssh-keygen -t rsa -C YOUR_EMAIL@DOMAIN.COM
  • You’ll receive the following prompts:
    Enter file in which to save the key (/home/vagrant/.ssh/id_rsa): – Press Enter
    Enter passphrase (empty for no passphrase): – Enter Password
    Enter same passphrase again: – Confirm Password
  • You should receive the following confirmation:
Your identification has been saved in /home/vagrant/.ssh/id_rsa.
Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
…
  • Print out the Public SSH Key & copy it:
cat ~/.ssh/id_rsa.pub
  • Go to your Github Settings, click New SSH Key button, enter a Title and paste in the public SSH Key, then click Add SSH Key.

Install Sublimetext on Mint using apt

https://www.sublimetext.com/docs/3/linux_repositories.html#aptInstall the GPG key:

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

Ensure apt is set up to work with https sources:

sudo apt-get install apt-transport-https

Select the channel to use:

Stable
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
Dev
echo "deb https://download.sublimetext.com/ apt/dev/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Update apt sources and install Sublime Text

sudo apt-get update
sudo apt-get install sublime-text