Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to fix EOF errors?
Hello.
The script should create a username and password on the remote computer, but when the script is run, errors appear:
[[email protected] ~]$ ssh [email protected] 'bash -s' < setup-lnxcfg-user
[email protected]'s password:
bash: line 5: $'\r': command not found
bash: line 53: warning: here-document at line 23 delimited by end-of-file (wanted `EOF')
bash: line 54: syntax error: unexpected end of file
#!/bin/bash
# setup-lnxcfg-user
# create lnxcfg user for Ansible automation
# and configuration management
# create lnxcfg user
getentUser=$(/usr/bin/getent passwd lnxcfg)
if [ -z "$getentUser" ]
then
echo "User lnxcfg does not exist. Will Add..."
/usr/sbin/groupadd -g 2002 lnxcfg
/usr/sbin/useradd -u 2002 -g 2002 -c "Ansible Automation Account" -s /bin/bash -m -d /home/lnxcfg lnxcfg
echo "lnxcfg:5555555555" | /usr/sbin/chpasswd
mkdir -p /home/lnxcfg/.ssh
fi
# setup ssh authorization keys for Ansible access
echo "setting up ssh authorization keys..."
cat << 'EOF' >> /home/lnxcfg/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8qmzR/QSI1VYhv4iPpCxmIvHBP4X6pvk2UfX3mepgaEtobkTyM2RiNrqf22dpcY/f [email protected]
EOF
chown -R lnxcfg:lnxcfg /home/lnxcfg/.ssh
chmod 700 /home/lnxcfg/.ssh
# setup sudo access for Ansible
if [ ! -s /etc/sudoers.d/lnxcfg ]
then
echo "User lnxcfg sudoers does not exist. Will Add..."
cat << 'EOF' > /etc/sudoers.d/lnxcfg
User_Alias ANSIBLE_AUTOMATION = lnxcfg
ANSIBLE_AUTOMATION ALL=(ALL) NOPASSWD: ALL
EOF
chmod 400 /etc/sudoers.d/lnxcfg
fi
# disable login for lnxcfg except through
# ssh keys
cat << 'EOF' >> /etc/ssh/sshd_config
Match User lnxcfg
PasswordAuthentication no
AuthenticationMethods publickey
EOF
# restart sshd
systemctl restart sshd
# end of script
Answer the question
In order to leave comments, you need to log in
I feel that you typed the script under Windows. You need to convert invisible end-of-line characters from vend format to unix format. The dos2unix program is perfect for this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question