Magento 2: Increase Admin Login Session Lifetime

This article shows how you can increase the admin login session lifetime in Magento 2.

Table of Contents

Problem

When you are a developer, it is frustrating to login to admin panel every 15 minutes or 30 minutes. It would be easy to set the admin login session lifetime for a longer period of time so that we don’t have to login continuously.

Cause

By default, the Magento admin login session timeouts in every 900 seconds, i.e. 900/60 = 15 minutes. Hence, you are inactive in Magento admin, then you have to re-login after every 15 minutes.

Solution

1) From Admin Panel

You can increase the admin login session lifetime to a higher value by going to:

STORES > Settings > Configuration > ADVANCED > Admin > Security > Admin Session Lifetime (seconds)

You can set the value in seconds.

3600 = 1 hour
86400 = 1 day (24 hours)
31536000 = 1 year

2) From Command Line

Instead of the admin panel, you can also set the admin session lifetime value from the command line.

Show current set value


bin/magento config:show admin/security/session_lifetime

Set your desired value


bin/magento config:set admin/security/session_lifetime 3600

Check database table

> SELECT * FROM core_config_data WHERE path = 'admin/security/session_lifetime';
+-----------+---------+----------+---------------------------------+----------+---------------------+
| config_id | scope   | scope_id | path                            | value    | updated_at          |
+-----------+---------+----------+---------------------------------+----------+---------------------+
|      6367 | default |        0 | admin/security/session_lifetime | 3600.    | 2021-10-07 22:31:47 |
+-----------+---------+----------+---------------------------------+----------+---------------------+

Hope this helps. Thanks.