Unable to create Home Directory for LDAP Login

I have linked my server with LDAP for ssh login. I get the Following error while logging in using ssh.

Could not chdir to home directory /home/ldap/sharukhk: No such file or directory

shahrukh@shahrukh:~/deploy$ ssh [email protected]
[email protected]'s password: 
Last login: Tue Sep 29 14:28:10 2015 from 10.200.100.245
Could not chdir to home directory /home/ldap/sharukhk: No such file or directory
-bash-4.1$ 

I have tried the following method to auto create home directory while login but it does not work

session required pam_mkhomedir.so skel=/etc/skel/ umask=0077

Solution 1:

This can be enabled using authconfig.

authconfig --enablemkhomedir --update

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Identity_Management_Guide/users.html#homedir-pammod

Solution 2:

same thing happens on on ubuntu 18.04 the fix is

# pam auth update

then select

[*] Create home directory on login

if you find out how to do this from the CLI please post me a comment