Всем привет.
Скрипт должен создать логин и пароль пользователя на удаленном компе, но при запуске скрипта появляются ошибки:
[lnxcfg@centos-2gb-nbg-vpn ~]$ ssh root@centos-2gb-nbg1-webserver 'bash -s' < setup-lnxcfg-user
root@centos-2gb-nbg1-webserver'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 lnxcfg@centos-2gb-nbg-vpn
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
Если что, то вот оригинал статьи
https://medium.com/@brad.simonin/learning-ansible-...