File tree Expand file tree Collapse file tree
ECCO-ACCESS/Cloud_access_to_ECCO_datasets Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # # Script to enable ssh connections,
4+ # # on EC2 instances where they are disabled by default
5+ # # (e.g., with JPL AMIs).
6+ # #
7+ # # Once this script runs successfully,
8+ # # it should be possible to login to the instance using ssh, e.g.:
9+ #
10+ # ssh -i "~/.ssh/your_key_pair.pem" jpluser@your_private_ip_address
11+
12+
13+ # Become root
14+ sudo -s
15+
16+ # Try to enable sshd
17+ systemctl enable sshd
18+ if [ $? -eq 0 ]; then
19+ echo " Enabled sshd successfully"
20+ else
21+ if [ $( readlink -f /etc/systemd/system/sshd.service) = " /dev/null" ]; then
22+ # Delete this /dev/null symlink
23+ rm -f /etc/systemd/system/sshd.service
24+ echo ' Deleted symlink to /dev/null'
25+
26+ # Re-try enabling sshd
27+ systemctl enable sshd
28+ if [ $? -eq 0] ; then
29+ echo " Enabled sshd successfully"
30+ else
31+ echo " Error: symlink deletion did not allow sshd to be enabled"
32+ exit 1
33+ else
34+ echo " Error: sshd not enabled successfully"
35+ fi
36+
37+ # Create symlink to the service (if it does not already exist)
38+ ln -s /etc/systemd/system/multi-user.target.wants/sshd.service /usr/lib/systemd/system/sshd.service
39+ echo " Created symlink to sshd.service"
40+
41+ # create new ssh keys
42+ ssh-keygen -q -N " " -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key
43+ echo " Created new ssh keys"
44+
45+ # start sshd service
46+ systemctl start sshd
You can’t perform that action at this time.
0 commit comments