Automatically login to console

From ezUnix
Jump to: navigation, search
                                    pdf_icon.png Download this article as a single PDF document 


Introduction


You probably did not know that you can have a user to login automatically without any password prompt. It's very useful in cases when you want certain things to be run automatically after boot and displayed on the screen. I use it myself with my http://www.wifiBSD.org project to display information about initial drive partitioning.


Implementation


And this is what you have to do to achieve this:

Edit /etc/gettytab and replace the default: line with following text:

default:
autologin|al:\
       :al=username:

username is the user you want to log in as automatically, e.g. root.
autologin or al is the name you say getty to use as default for console.
Remember this username needs to exist on the system.

Next edit /etc/ttys and replace the console line with :

console "/usr/libexec/getty al"         vt100   on secure

Hint: Replace the default shell of the user you want to login as with your custom script if you want it to be executed when the user logs in automatically. Run:

# vipw

And put there something like:

username:*:0:0:Admin user:/root:/etc/rc.start

This "username" user will execute /etc/rc.start script with root privileges. The "username" is just an example, it can be anything, for example "admin".

Final step


Finally you need to restart your system so init can rerun getty with your new options.

Remember to always use shutdown(8) when shutting down. Never simply use reboot(8). reboot(8) will not properly run shutdown RC scripts.

# shutdown -r now



That's all folks. Marcin


<comments />