Skip to content

Commit b0f50f5

Browse files
committed
fixes/updates to sshd_enable.sh
1 parent b0fa7fd commit b0f50f5

2 files changed

Lines changed: 41 additions & 24 deletions

File tree

ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh

100644100755
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/bin/bash
22

3-
# # Shell script for setting up conda, jupyter, essential Python packages on an AWS EC2 instance.
4-
# # Assumes that the ECCO-v4-Python-Tutorial Github repository has already been downloaded using:
5-
# sudo dnf update -y
6-
# sudo dnf install git -y
7-
# cd ~
8-
# git clone https://github.com/ECCO-GROUP/ECCO-v4-Python-Tutorial.git
9-
10-
# # Then run this script:
11-
# sudo chmod 755 ~/ECCO-v4-Python-Tutorial/ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh
12-
# ~/ECCO-v4-Python-Tutorial/ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh
3+
# Shell script for setting up conda, jupyter, essential Python packages on an AWS EC2 instance.
4+
# Assumes that the ECCO-v4-Python-Tutorial Github repository has already been downloaded using:
5+
#
6+
# $ sudo dnf update -y
7+
# $ sudo dnf install git -y
8+
# $ cd ~
9+
# $ git clone https://github.com/ECCO-GROUP/ECCO-v4-Python-Tutorial.git
1310

11+
# Then run this script:
12+
#
13+
# $ sudo chmod 755 ~/ECCO-v4-Python-Tutorial/ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh
14+
# $ ~/ECCO-v4-Python-Tutorial/ECCO-ACCESS/Cloud_access_to_ECCO_datasets/jupyter_env_setup.sh
1415

1516

1617
# # Start body of script
@@ -118,6 +119,6 @@ if [ $earthdata_cred_stored -eq 0 ]; then
118119
read -sp 'NASA Earthdata password: ' passvar
119120
echo -e "machine urs.earthdata.nasa.gov\n login ${uservar}\n password ${passvar}\n" >> ~/.netrc
120121

121-
echo -e "\n${red_start}NASA Earthdata authentication info archived in ~\/.netrc${nocolor_start}"
122+
echo -e "\n${red_start}NASA Earthdata authentication info archived in ~/.netrc${nocolor_start}"
122123
fi
123124
sudo chmod 400 ~/.netrc
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#!/bin/bash
22

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.:
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.:
99
#
10-
# ssh -i "~/.ssh/your_key_pair.pem" jpluser@your_private_ip_address
10+
# $ ssh -i "~/.ssh/key_pair.pem" jpluser@private_ip_address
11+
1112

1213

13-
# Become root
14-
sudo -s
15-
1614
# Try to enable sshd
1715
systemctl enable sshd
1816
if [ $? -eq 0 ]; then
@@ -25,22 +23,40 @@ else
2523

2624
# Re-try enabling sshd
2725
systemctl enable sshd
28-
if [ $? -eq 0] ; then
26+
if [ $? -eq 0 ] ; then
2927
echo "Enabled sshd successfully"
3028
else
3129
echo "Error: symlink deletion did not allow sshd to be enabled"
3230
exit 1
31+
fi
3332
else
3433
echo "Error: sshd not enabled successfully"
34+
fi
3535
fi
3636

3737
# 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"
38+
if [ ! -f /usr/lib/systemd/system/sshd.service ]; then
39+
ln -s /etc/systemd/system/multi-user.target.wants/sshd.service /usr/lib/systemd/system/sshd.service
40+
echo "Created symlink to sshd.service"
4041

4142
# create new ssh keys
4243
ssh-keygen -q -N "" -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key
4344
echo "Created new ssh keys"
4445

4546
# start sshd service
4647
systemctl start sshd
48+
echo "Started sshd"
49+
echo "Now you can login to your instance using ssh, e.g.:"
50+
echo '$ ssh -i "~/.ssh/your_key_pair.pem" jpluser@private_ip_address'
51+
52+
53+
# move git repo to ssh user's directory and change ownership (if requested)
54+
read -p 'Move ECCO-v4-Python-Tutorial repo to different user? [Y/N] ' move_opt
55+
if [ $move_opt == "Y"] || [ $move_opt == "y" ]; then
56+
read -p 'User name of new owner [jpluser for JPL]: ' ssh_user
57+
cd /home
58+
mv ./ssm-user/ECCO-v4-Python-Tutorial ./${ssh_user}/
59+
echo "Moved ECCO-v4-Python-Tutorial repo to /home/${ssh_user}/"
60+
chown -R ${ssh_user}:${ssh_user} ./{ssh_user}/ECCO-v4-Python-Tutorial
61+
echo "Changed owner and group of git repo to ${ssh_user}"
62+
fi

0 commit comments

Comments
 (0)