This was inspired by the need to access the Raspberry Pi via SSH or VNC without having a monitor, mouse, or keyboard. This is also very useful when moving from network to network. This allows your Raspberry Pi to login automatically, obtain an IP address, and email you the IP address. This uses a Gmail SMTP server and assumes you have a valid Gmail address. You will need to alter the mail servers a bit for other mail providers.
Let’s Get Started
You need a Raspberry Pi running any version of Linux with an ethernet port although the instructions state Kali. You should be comfortable navigating a Linux operating system and be comfortable using the sudo command in a CLI.
Step 1 – Auto-Login Root or whatever user you choose
Modify the lightdm config file.
root@kali:~# sudo nano /etc/lightdm/lightdm.conf
Locate the section in lightdm.conf labeled [Seat:*] and then #autologin-user= and #autologin-user-timeout=0 within it. We will be removing the comments and adding the user root. There are two sections that look similar so make sure that you are working with the right lines.
autologin-user=root
autologin-user-timeout=0
This is how they should look when you are done.
Step 2 – Obtain IP Address and Send Email
Install SendEmail
root@kali:~# sudo apt-get install sendemail
Create a script to Obtain IP Address and Email it to you
root@kali:~# sudo nano getip.sh
Change the from, to, subject, message-filename, smtp server and port, and the username
Copy and Paste the text below between the ****
***************************************************************
#Get IP Address and save to a text file
ifconfig | grep -v 127.0.0.1 | awk ‘/inet / {gsub(“addr:”, “”, $2); print $2}; /netmask / {gsub(“netmask”, “”, $2); print $4};’ > myip.txt
#Send IP Address Via sendEmail
sendemail -f from@email.com -t to@email.com -u “Kali IP Address” -o message-file=fire.sh -s smtp server:port -xu from@email.com -xp password
***************************************************************
Press Control + O
to save
Press Control + X
to exit
Make your script executable
root@kali:~# sudo chmod +x getip.sh
Execute Script on Startup
root@kali:~#sudo crontab -e
The following line of code executes your script 120 seconds after a reboot.
At the very bottom for the code add the following:
@reboot sleep 120; bash /path/to/your/script/getip.sh
It should look similar to this
Press Control + O
to save
Press Control + X
to exit
Step 3 – Test
Reboot your Pi ‘sudo reboot
‘, and test. If the Pi automatically logs in and emails you the IP address, it was successful.