-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshconfig
More file actions
executable file
·43 lines (31 loc) · 1.22 KB
/
sshconfig
File metadata and controls
executable file
·43 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# Colors for echo formatting
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
pi_default_user="pi"
echo "Enter a name for this ssh key: "
read keyname
# Create our ssh keys
ssh-keygen -t ed25519 -f ~/.ssh/"$keyname" -P ""
# Get the ip address for the pi listed in the inventory file
pi_ip=$(ansible --list-hosts pi4 | tail -1 | xargs)
echo -e "${GREEN}=============================================${NC}"
echo -e "${GREEN}RASPBERRY PI DEFAULT PASSWORD: 'raspberry'${NC}"
echo -e "${GREEN}=============================================${NC}"
# Copy the public key to the pi
ssh-copy-id -i ~/.ssh/"$keyname".pub "$pi_default_user"@"$pi_ip"
# Ensure the ssh-agent is started with each new terminal session
ansible localhost -m blockinfile -a "path=~/.bashrc block='eval \$(ssh-agent)\nssh-add ~/.ssh/${keyname}'"
# Start the ssh agent and add our private key to inventory
is_started=$(echo $SSH_AGENT_SOCK)
if [ "$is_started" = "" ]
then
echo "Starting SSH Agent"
eval $(ssh-agent)
fi
ssh-add -q ~/.ssh/"$keyname"
echo "Dropping you into a new bash session to keep the agent running..."
echo -e "${GREEN}Now try logging in with:${NC} ${CYAN}ssh $pi_default_user@$pi_ip${NC}"
bash -i