Ask Your Question

how to login a tty in startup

asked 2015-10-05 05:18:15 -0500

hamedBB gravatar image

I want to execute some command on special tty (for example tty2) in my linux startup so every time the system reboots this commands execute on that tty. I used this link to do : It works fine but problem is , in startup I need to login desired tty then execute the commands. Is there any way to login a tty by some command at the beginning? Thanks

edit retag flag offensive close merge delete



It would help to know specifically what you want to accomplish by this method. I suspect there is a better method, perhaps rc.local as @Florian suggested, or a service unit.

randomuser gravatar imagerandomuser ( 2015-10-05 22:53:41 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2015-10-06 02:47:06 -0500

hamedBB gravatar image

updated 2015-10-06 06:27:08 -0500

I solved the problem somehow.

first I make desired ttys login automatically by changing /etc/inittab, change below :

2:2345:respawn:/sbin/mingetty tty[1-6] -> 2:2345:respawn:/sbin/mingetty tty[1-6] --autologin USER_NAME

then I make a script which check tty index and execute command on a tty which I wanted to, code below :

if [[ $(tty) = /dev/tty[1-6] ]]; then MY_COMMAND fi

then I just put my script at /root/.bash_profile

edit flag offensive delete link more

answered 2015-10-05 14:22:09 -0500

florian gravatar image

updated 2015-10-05 14:23:39 -0500

Hi @hamedBB, Welcome to ask.fedora.

It may not be exactly what you want but you could use rc.local for executing commands on boot. Check out this Q/A and this Q/A for more information and setup.

You are not getting a feedback from this service as you would get it in a plain terminal. Not sure if you need it...

edit flag offensive delete link more



STDOUT and STDERR goes to the journal, you'd get feedback this way.

randomuser gravatar imagerandomuser ( 2015-10-05 22:54:08 -0500 )edit

You are right I didn't need that service :)

hamedBB gravatar imagehamedBB ( 2015-10-06 02:47:51 -0500 )edit

answered 2015-10-05 12:43:40 -0500

msx gravatar image


"Is there any way to login a tty by some command at the beginning?" Yes, it has been there since at least 1997. Please try: $ man chvt


edit flag offensive delete link more


  1. Your answer is really not friendly. If a users asking for help is usually because he or she doesn't know a command or a function, or so. And that doesn't change, no matter how long this command is out there.
  2. The way I read the question, your answer is not answering his question. Isn't @hamedBB asking how to execute commands on tty without the need of first logging into the corresponding tty? chvt N makes N the active tty but is doesn't log you in.
florian gravatar imageflorian ( 2015-10-05 14:15:05 -0500 )edit

Question Tools

1 follower


Asked: 2015-10-05 05:18:15 -0500

Seen: 1,402 times

Last updated: Oct 06 '15