We use “expect” to auto login as root, reference here(expect)

 
1.  Install “expect” on your machine

sudo apt-get install expect

 
2. write expect script(auto_login_root.sh)

#!/usr/bin/expect
set password "here_is_your_root_password"
spawn sudo -i
send "$password\r"
interact

Note :  command reference
 
3. execute expect script

expect auto_login_root.sh