Skip to content
Home » News » Admin Session Lifetime in Magento 2: How to change it? 

Admin Session Lifetime in Magento 2: How to change it? 

Magento automatically logs you out of the Admin panel if you’re inactive for a certain period of time. It is done for security reasons to protect your store. However, if Admin Session Lifetime in Magento 2 – the timeout – is too short, you will need to keep logging in, which can be rather annoying and inconvenient, especially if you’re working on lengthy tasks.

How Backend Timeouts Work in Magento

In Magento 2.1 and newer versions, timeouts are connected to your browser. This means if you close your browser, you’ll get logged out automatically. The session also automatically ends when no activity happens in the backend during the set period of time. You can change the Admin session lifetime in Magento 2, that is set how long a session stays active, from as short as 1 minute to as long as 1 year.

Steps to Change the Magento Backend Timeout via Admin Panel

If you work in the admin panel a lot, short timeouts can slow you down. Thus, changing the timeout to a longer duration can make things easier while still keeping your store secure.

Follow these simple steps to adjust the Admin session lifetime in Magento 2:

  1. Log in to the Admin Panel
    • Use your admin username and password.
Magento Login
  1. Go to the Settings
    • Click on Stores in the menu and choose Configuration
Stores Configuration section in Magento backend
  • Choose Advanced and then Admin
Advanced admin section in Magento backend
  1. Find the Timeout Setting
    • Open Security and look for Admin Session Lifetime (seconds). This setting controls how long you stay logged in.
Security - Admin Session Lifetime section
  1. Set a New Timeout
    • Change the number to what works best for you:
      • 3600 seconds (1 hour) for regular use.
      • 86400 seconds (1 day) for longer access.
  2. Save the Changes
    • Click Save Config in the upper corner to apply the new settings.

Steps to Update Admin Session Lifetime via CLI

It is also possible to change the Admin Session Lifetime using the Magento CLI (bin/magento): 

bin/magento config:set admin/security/session_lifetime <lifetime_in_seconds>
  1. Navigate to the root directory of your Magento installation.
  2. Run the above command.

Replace <lifetime_in_seconds> with the desired session lifetime in seconds. For example, to set the session lifetime to 1 hour (3600 seconds), run:

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

3.  Flush the Cache: After changing the configuration, clear the cache to ensure the change is applied:

bin/magento cache:flush

You can verify the setting has been updated using the following command:

bin/magento config:show admin/security/session_lifetime

This will show the current session lifetime value.

Simple Tips for Changing Admin Session Lifetime in Magento 2

  • If you tend to spend a lot of time in the admin panel, consider using a longer timeout.
  • If you use it only occasionally or want extra security, consider using a shorter timeout. 

Conclusion

Adjusting the Admin session lifetime in Magento 2 is quick and easy. Just change the Magento backend timeout to fit your work style anytime you need.

Author

Leave a Reply

Your email address will not be published. Required fields are marked *