Skip to content

Instantly share code, notes, and snippets.

@gustavoapolinario
Last active June 16, 2019 12:38
Show Gist options
  • Save gustavoapolinario/d542aaa6ec5b5b2b7eae7301011cf7b2 to your computer and use it in GitHub Desktop.
Save gustavoapolinario/d542aaa6ec5b5b2b7eae7301011cf7b2 to your computer and use it in GitHub Desktop.
This script will create a new stpf user with non interactive mode.
#!/usr/bin/expect -f
set newUser [lindex $argv 0]
set newPassword [lindex $argv 1]
spawn passwd $newUser
expect "New password:"
send "$newPassword\r"
expect "Retype new password:"
send "$newPassword\r"
expect "passwd: all authentication tokens updated successfully."
send "exit\r"
expect eof
#!/bin/sh
# sudo ./create-user-ftp.sh NEW_USER
if [ "$#" -eq 0 ]; then
me=`basename "$0"`
echo "./$me [USERNAME]" >&2
exit 1
fi
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
newUser=$1
echo "new user: $newUser"
newPassword=$(</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo "")
echo "new password: $newPassword"
#sftp-user create $newUser
/home/ec2-user/create-user-ftp2.sh $newUser $newPassword
#sudo passwd $newUser
/home/ec2-user/change-password.sh $newUser $newPassword
usermod -G sftp $newUser
#!/usr/bin/expect -f
set newUser [lindex $argv 0]
set newPassword [lindex $argv 1]
spawn sftp-user create $newUser
expect "Enter password:"
send "$newPassword\r"
send "exit\r"
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment