Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Last active December 14, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simkimsia/5126919 to your computer and use it in GitHub Desktop.
Save simkimsia/5126919 to your computer and use it in GitHub Desktop.
change shell for any user to use /bin/bash
#!/usr/bin/expect -f
###
#
# Copyright (c) 2013 KimSia Sim
#
# Ubuntu 12.10 based change shell for users
# Run this by executing the following from a fresh install of Ubuntu 12.10 server:
#
# expect -c "$(curl -fsSL https://raw.github.com/gist/5126919)" <username> <password>
#
# Be sure to replace <username> with your intended username and <password> with your intended password.
# Also, run this as root, unless you enjoy failing.
# Be sure you have installed expect. Run apt-get install expect before this.
#
# Its handy to install 'screen' if you want to ensure your remote connection to
# a server doesn't disrupt the installation process. If you want to do this, just
# do the following before running the main bash command:
#
# apt-get install screen -y
# screen
#
# To recover your session if you are disconnected, ssh to your server as root again,
# and type:
#
# screen -x
#
# Dependencies:
# - curl
#
# Todo:
# - SSL Configuration
#
###
set CHANGESHELL_FOR_USER [lindex $argv 0];
set PASSWORD_OF_USER [lindex $argv 1];
########################################
## switch to another user
## read this http://stackoverflow.com/a/1988255/80353
########################################
sudo -u $CHANGESHELL_FOR_USER -H sh -c "chsh -s /bin/bash"
expect "*?assword:*" {send -- "$PASSWORD_OF_USER\r";}
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment