Solution for Magento 2.1+
Since Magento 2.1 the admin session lifetime is always "session", i.e. until the browser is closed. This has been might have been introduced for security reasons.
The relevant code is in Magento\Backend\Model\Session\AdminConfig
:
/**
* Set session cookie lifetime to session duration
*
* @return $this
*/
protected function configureCookieLifetime()
{
return $this->setCookieLifetime(0);
}
If you want to change this behavior, you can add a plugin for this class with the following interceptor method:
public function beforeSetCookieLifetime()
{
$lifetime = $this->scopeConfig->getValue(
\Magento\Framework\Session\Config::XML_PATH_COOKIE_LIFETIME,
\Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
return [$lifetime, \Magento\Framework\Session\Config::COOKIE_LIFETIME_DEFAULT];
}
Where $this->scopeConfig
should be an instance of \Magento\Framework\App\Config\ScopeConfigInterface
, injected via constructor parameter.
This way the cookie lifetime is used from configuration, just as in the frontend.
Note that the configuration in Stores > Configuration > Advanced > Admin Security > Session Lifetime does not have any effect on the cookies anymore! It is used to determine Redis session lifetime, so if you increase the cookie lifetime, you should also increase this value.