Skip to content

Commit 8f15489

Browse files
committed
fixes to sshd_enable.sh
1 parent ddd8c27 commit 8f15489

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

ECCO-ACCESS/Cloud_access_to_ECCO_datasets/sshd_enable.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44
# on EC2 instances where they are disabled by default
55
# (e.g., with JPL AMIs).
66
#
7+
# This script must be run as root, otherwise an error is returned:
8+
# $ sudo ./sshd_enable.sh
9+
#
710
# Once this script runs successfully,
811
# it should be possible to login to the instance using ssh, e.g.:
912
#
1013
# $ ssh -i "~/.ssh/key_pair.pem" jpluser@private_ip_address
1114

1215

16+
# Return error if not running as root
17+
if [ $( whoami ) != "root" ]; then
18+
echo "Error: this script must be run as root"
19+
echo "Please re-run using sudo, e.g.:"
20+
echo "$ sudo ./sshd_enable.sh"
21+
exit 1
22+
fi
23+
1324

1425
# Try to enable sshd
1526
systemctl enable sshd
@@ -23,7 +34,7 @@ else
2334

2435
# Re-try enabling sshd
2536
systemctl enable sshd
26-
if [ $? -eq 0 ] ; then
37+
if [ $? -eq 0 ]; then
2738
echo "Enabled sshd successfully"
2839
else
2940
echo "Error: symlink deletion did not allow sshd to be enabled"
@@ -38,6 +49,7 @@ fi
3849
if [ ! -f /usr/lib/systemd/system/sshd.service ]; then
3950
ln -s /etc/systemd/system/multi-user.target.wants/sshd.service /usr/lib/systemd/system/sshd.service
4051
echo "Created symlink to sshd.service"
52+
fi
4153

4254
# create new ssh keys
4355
ssh-keygen -q -N "" -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key
@@ -51,12 +63,12 @@ echo '$ ssh -i "~/.ssh/your_key_pair.pem" jpluser@private_ip_address'
5163

5264

5365
# 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
66+
read -p 'Move ECCO-v4-Python-Tutorial repo to different user? (Y/[N]) ' move_opt
5567
if [ $move_opt == "Y"] || [ $move_opt == "y" ]; then
5668
read -p 'User name of new owner [jpluser for JPL]: ' ssh_user
5769
cd /home
5870
mv ./ssm-user/ECCO-v4-Python-Tutorial ./${ssh_user}/
5971
echo "Moved ECCO-v4-Python-Tutorial repo to /home/${ssh_user}/"
60-
chown -R ${ssh_user}:${ssh_user} ./{ssh_user}/ECCO-v4-Python-Tutorial
72+
chown -R ${ssh_user}:${ssh_user} ./${ssh_user}/ECCO-v4-Python-Tutorial
6173
echo "Changed owner and group of git repo to ${ssh_user}"
6274
fi

0 commit comments

Comments
 (0)