User gets instantly disconnected after connection successful on a chrooted SSH - ssh

I configured a jail with Chroot in SSH following this tutorial.
I found another question on StackOverflow dealing with the same problem, however the answers didn't work for me either.
The auth.log file contains the following:
Mar 16 18:36:06 *** sshd[30509]: Accepted password for thenewone from x.x.x.x port 49583 ssh2
Mar 16 18:36:06 *** sshd[30509]: pam_unix(sshd:session): session opened for user thenewone by (uid=0)
Mar 16 18:36:07 *** sshd[30509]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Mar 16 18:36:07 *** sshd[30509]: lastlog_openseek: Couldn't stat /var/log/lastlog: No such file or directory
Mar 16 18:36:07 *** sshd[30509]: pam_unix(sshd:session): session closed for user thenewone
My sshd_config file contains the following:
Match User thenewone
ChrootDirectory /home/thenewone
AllowTcpForwarding no
X11Forwarding no
My /home/thenewone directory is owned by root:root and contains the chrooted system (all files but /home/thenewone/home/thenewone owned by root:root)
I don't understand why the connection is successful then simply close.

Problem found: some binaries dependencies were missing, even for the shell associated with the chrooted account...
Shell failed to load --> disconnection!
If you are experiencing the same trouble as mine, use ldd <binary> to find all needed dependencies in the chroot jail

Related

Systems start for slapd failed and timeout

I try to install openldap(v2.4.44) using puppet agent --test in a Centos 7 environment and received this error
Error: Systems start for slapd failed!
journalctl log for slapd:
systemd[1]: Starting OpenLDAP Server Daemon...
runuser[110317]: pam_unix(runuser:session): session opened for user ldap by
(uid=0)
runuser[110317]: pam_unix(runuser:session): session closed for user ldap
tlsmc_get_pin: INFO: Please note the extracted key file will not be protected
with a PIN any more, however it will be still protected at least by file
permissions.
tlsmc_get_pin: INFO: Please note the extracted key file will not be protected
with a PIN any more, however it will be still protected at least by file
permissions.
tlsmc_get_pin: INFO: Please note the extracted key file will not be protected
with a PIN any more, however it will be still protected at least by file
permissions.
... loop until timeout
Note: This happened if I installed manually as well
Might be environment issue as well because I tried in different environment it seems fine.
Anyone have any clue?

How to authenticate ldap user and login on server as GUI ,it should login on server directly via GUI

I am new to System admin My problem is : In my department there are 30 students in 1st year and 30 students in 2nd year which are divided into two groups lets say group1 and group2 which need to login as ldap user via Ubuntu(14.04) GUI through any System connected to LAN.Every users home directory should be created on server side ,It should mount while login as GUI in ubuntu14.04, No other user should access anyone else home directory except by self.
[I don't want authenticating user to ldap-server and creating home directory on local machine ,instead I want central directory on server side,It should looks like login to server.]
Server Side : Ubuntu 14.04
I tried this and it works fine for me.
Client side : Ubuntu14.04
I tried this , it also works
but the issue is , this tutorial creates home directory on local machine instead of mounting server directory.I know from where it does.
I want : If i login through ldap user It should login on server via GUI not on local machine home directory.
on client side file "/var/log/auth.log"
Jul 28 11:53:06 issc systemd-logind[674]: System is rebooting.
Jul 28 11:53:23 issc systemd-logind[650]: New seat seat0.
Jul 28 11:53:23 issc systemd-logind[650]: Watching system buttons on /dev/input/event1 (Power Button)
Jul 28 11:53:23 issc systemd-logind[650]: Watching system buttons on /dev/input/event4 (Video Bus)
Jul 28 11:53:23 issc systemd-logind[650]: Watching system buttons on /dev/input/event0 (Power Button)
Jul 28 11:53:24 issc sshd[833]: Server listening on 0.0.0.0 port 22.
Jul 28 11:53:24 issc sshd[833]: Server listening on :: port 22.
Jul 28 11:53:25 issc lightdm: PAM unable to dlopen(pam_kwallet.so): /lib/security/pam_kwallet.so: cannot open shared object file: No such file or directory
Jul 28 11:53:25 issc lightdm: PAM adding faulty module: pam_kwallet.so
Jul 28 11:53:25 issc lightdm: pam_unix(lightdm-greeter:session): session opened for user lightdm by (uid=0)
Jul 28 11:53:25 issc systemd-logind[650]: New session c1 of user lightdm.
Jul 28 11:53:25 issc systemd-logind[650]: Linked /tmp/.X11-unix/X0 to /run/user/112/X11-display.
Jul 28 11:53:26 issc lightdm: PAM unable to dlopen(pam_kwallet.so): /lib/security/pam_kwallet.so: cannot open shared object file: No such file or directory
Jul 28 11:53:26 issc lightdm: PAM adding faulty module: pam_kwallet.so
Jul 28 11:53:26 issc lightdm: pam_succeed_if(lightdm:auth): requirement "user ingroup nopasswdlogin" not met by user "scicomp"
Jul 28 11:53:29 issc lightdm: PAM unable to dlopen(pam_kwallet.so): /lib/security/pam_kwallet.so: cannot open shared object file: No such file or directory
Please help me, i tried many tutorial online and every tutorial looks like same ,like this one.I am trying from last 2 weeks its not working.Thank you for your time.
You need to install and configure autofs for this to work. autofs will automatically mount user's home directories on the client machine from an NFS server. I'm not sure about creating them on the server on the fly, but if it does work, you will likely need to enable the pam_mkhomedir module in the appropriate /etc/pam.d file(s), as described here
Yep! I tried and worked for me.
**Server Side :** Package require to install :
$ sudo apt-get install nfs-kernel-server
Updated in below file like this
abdulrahim#issc-ldap:/ldap/batch2016part2$ sudo vi /etc/exports
#/homes 198.1.10.*(fsid=0,rw,insecure,no_subtree_check,sync)
/ldap/batch2015part1/home 198.1.10.*(fsid=1,rw,insecure,no_subtree_check,sync)
/ldap/batch2015part2/home 198.1.10.*(fsid=2,rw,insecure,no_subtree_check,sync)
Exported as per below::::
abdulrahim#issc-ldap:/ldap/batch2016part2$ sudo exportfs -r
root#issc-ldap:/ldap/rnd# showmount -e 198.1.10.45
Export list for 198.1.10.45:
/ldap/batch2015part1/home
/ldap/batch2015part2/home
**On Client Side :** Package require to install :
$ sudo apt-get install nfs-kernel-client
NOW ON CLIENT SIDE mount,permission ,ownership::::::
$ sudo gedit /etc/fstab
#####below are partition mounted from server
198.1.10.45:/ldap/batch2015part1/home /ldap/batch2015part1/home nfs nfsvers=3,sync 0 3
198.1.10.45:/ldap/batch2015part2/home /ldap/batch2015part2/home nfs nfsvers=3,sync 0 4
### or like this below
198.1.10.45:/ldap/batch2015part1/home /ldap/batch2015part1/home nfs noauto,x-systemd.automount 0 3
198.1.10.45:/ldap/batch2015part2/home /ldap/batch2015part2/home nfs noauto,x-systemd.automount 0 4
Now mount all pertition from server side as per below : :::::
$ sudo mount -a
Check mounted partion by below commands
$ df -h

Jenkins Slave Permission Denied while copying slave.jar

I get a permissions denied but don't know why. From my jenkins master I was able to run the following command using ssh-rsa-key
scp /var/cache/jenkins/war/WEB-INF/slave.jar jenkins#<my_slave_host>:/var/jenkins/
Note: I did manually create /var/jenkins/ on the my slave host when i saw it didn't exist and made it owned by the jenkins user. My master jenkins is configured to use the jenkins#mySlaveHost using .ssh keys.
Any ideas why I'm getting a permissions denied? What is it trying to do?
Here's the log from master jenkins after clicking [Lauch slave agent] button:
[02/27/15 15:18:01] [SSH] Opening SSH connection to <my_slave_host>:22.
[02/27/15 15:18:02] [SSH] Authentication successful.
[02/27/15 15:18:03] [SSH] The remote users environment is:
BASH=/bin/bash
BASHOPTS=cmdhist:complete_fullquote:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING=set
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="3" [2]="11" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
BASH_VERSION='4.3.11(1)-release'
CATALINA_HOME=/opt/tomcat/current
DIRSTACK=()
EUID=107
GROUPS=()
HOME=/var/lib/jenkins
HOSTNAME=*********** REMOVED***********
HOSTTYPE=x86_64
IFS=$' \t\n'
JAVA_HOME=/usr/lib/jvm/java-7-oracle
LANG=en_US.UTF-8
LOGNAME=jenkins
MACHTYPE=x86_64-pc-linux-gnu
MAIL=/var/mail/jenkins
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PIPESTATUS=([0]="0")
PPID=10592
PS4='+ '
PWD=/var/lib/jenkins
SHELL=/bin/bash
SHELLOPTS=braceexpand:hashall:interactive-comments
SHLVL=1
SSH_CLIENT='10.57.13.32 34436 22'
SSH_CONNECTION='10.57.13.32 34436 10.57.6.42 22'
TERM=dumb
UID=107
USER=jenkins
XDG_RUNTIME_DIR=/run/user/107
XDG_SESSION_ID=42
_=']'
[02/27/15 15:18:03] [SSH] Checking java version of java
[02/27/15 15:18:04] [SSH] java -version returned 1.7.0_76.
[02/27/15 15:18:04] [SSH] Starting sftp client.
[02/27/15 15:18:04] [SSH] Copying latest slave.jar...
hudson.util.IOException2: Could not copy slave.jar into '/var/jenkins' on slave
at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1019)
at hudson.plugins.sshslaves.SSHLauncher.access$300(SSHLauncher.java:133)
at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:709)
at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:696)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: hudson.util.IOException2: Could not copy slave.jar to '/var/jenkins/slave.jar' on slave
at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1016)
... 7 more
Caused by: com.trilead.ssh2.SFTPException: Permission denied (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation.)
at com.trilead.ssh2.SFTPv3Client.openFile(SFTPv3Client.java:1201)
at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1074)
at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1055)
at hudson.plugins.sshslaves.SFTPClient.writeToFile(SFTPClient.java:93)
at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1008)
... 7 more
[02/27/15 15:18:04] Launch failed - cleaning up connection
[02/27/15 15:18:04] [SSH] Connection closed.
Edit:
Here's /var/jenkins on the slave:
$ ls -al
total 436
drwxr-xr-x 2 jenkins jenkins 22 Feb 27 15:17 .
drwxr-xr-x 14 root root 4096 Feb 27 15:12 ..
-rw-r--r-- 1 jenkins jenkins 439584 Feb 27 15:17 slave.jar
As for SFTP, I do not think it is enabled, can you point me to any docs that says SFTP is a pre-requisite for a slave? All the pages I've seen do not mention SFTP.
It looks like the problem is tied to your Remote root directory setting. That needs to be the location of the slave.jar, as Jenkins will try to execute it from there.
As for the permissions, the Remote Root Directory (whatever you set it to) needs to be configured to allow Jenkins to access it.
Therefore, if you change your Remote root directory setting to be /var/jenkins/ in your case, it should launch the Jenkins slave successfully.
Granting
sudo chmod -R 777 /var/lib/jenkins
works for me
sudo chmod -R 777 /var/jenkins
Make sure that the location's permissions where the jar needs to be copied is as the logged in user (i.e. jenkins).
check for permisison using:
ls -l directory_name
Most probably you'll find another owner, so change the owner with:
chown -R username:username directory_name
That worked for me !
For anyone with an external drive, check that it's mounted correct:
drwxrwxrwx+ 2 App admin 68 Aug 25 19:33 Jenkins_Support
drwxrwxr-x 19 App staff 714 Sep 25 10:46 Jenkins_Support 1
This might be a problem
If you changed a user to connect to slave, please also make sure slave destination directory is empty (not containing slave.jar copied there by previous user).
This is kind of stupid, but costed me a time.
In ubuntu terminal check
service ufw status
if active
service ufw stop
In redhat terminal check
service iptables status
if active
service iptables stop
service ip6tables status
if active
service ip6tables stop
then check jenkins-slave-node status

SSHD Gives error could not open Authorized Keys, although permissions seem correct

I'm unable to login to SSH because of the following error in /var/log/secure (according to the debug logs):
Dec 19 18:01:05 hostname sshd[25119]: debug1: trying public key file /root/.ssh/authorized_keys
Dec 19 18:01:05 hostname sshd[25119]: debug1: Could not open authorized keys '/root/.ssh/authorized_keys': Permission denied
I have the following permissions set on root
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod go-wrx ~
ls -lah gives the following output for those directories:
drwx------. 6 root root 4.0K Dec 19 17:46 root
drwx------. 2 root root 4.0K Dec 19 17:41 .ssh
-rw-------. 1 root root 416 Dec 19 17:12 authorized_keys
I know the key I'm using is correct, as I just setup another server with it without any problems.
I'm running: CentOS release 6.4 (Final)
I've added my sshd config in case there's something misconfigured in there that might be causing the issue:
# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2
# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024
# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel DEBUG
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
StrictModes no
#MaxAuthTries 6
#MaxSessions 10
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes
# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server
Any ideas would be much appreciated.
If the permissions are correct, SELinux might still be preventing sshd from opening the file.
Try fixing the labels inside the .ssh directory (and maybe $HOME):
restorecon -FRvv ~/.ssh
If the user account uses non-standard home path, default labels for the path need to be added to the local configuration first:
semanage fcontext -a -t ssh_home_t "/srv/custom/\.ssh(/.*)?"
(I'm intentionally not suggesting disabling SELinux or setting it to the permissive mode.)
In case if SELinux enabled:
$ getenforce
Enforcing
to temporary enable pub-key ssl login to non-standard user home directory location run:
$ sudo chcon -t ssh_home_t /srv/jenkins/.ssh/authorized_keys /srv/jenkins/.ssh
$ ls -ldZ /srv/jenkins/.ssh/authorized_keys /srv/jenkins/.ssh/
drwxr-xr-x. jenkins jenkins system_u:object_r:ssh_home_t:s0 /srv/jenkins/.ssh/
-rw-r--r--. jenkins jenkins system_u:object_r:ssh_home_t:s0 /srv/jenkins/.ssh/authorized_keys
See https://linux.die.net/man/8/ssh_selinux for the details.
To make SELinux settings permanent run:
$ sudo semanage fcontext -a -t ssh_home_t /srv/jenkins/.ssh/authorized_keys
$ sudo semanage fcontext -a -t ssh_home_t /srv/jenkins/.ssh
$ sudo restorecon -R -v /srv/jenkins/.ssh/
You hit this if you are on modern RHEL, Oracle Linux, CentOS.
I was struggling to use key authentication as well.
Could not open authorized keys '/home/myUserName/.ssh/authorized_keys2': Permission denied
Had checked all the above things when I ended up here (first link on google).
I realize that this is an old post but I will add it here in case somebody else has the same problem as me and end up here.
I had owner of the authorized_keys file to "root", so changing it with:
chown myUserName authorized_keys2
Solved it for me.
I've spent a good couple hours with this crap. Reading loads of illuminated solutions to the issue, here is a boil down of what none of them say clearly.
Sumarizing.
The following applies to these files:
~/.ssh/
~/.ssh/authorized_keys
Ownership
The owner and group must be the logging user.
Permissions
Group and public permissions must be set to 0 (no permissions). Yes! sshd thinks you're stupid by default.
And of course, the owner must be allowed to read.
Note. Permissions such as 777 give the same error as 000, even though it is an application policy to not open the file. This was probably the biggest source of confusion during this whole endeavour.
Users
All logging users must exist. By logging users we mean:
The user sent with the url ssh root#localhost
Or, the user in the public key present on the client machine (~/.ssh/id_rsa.pub in the client, not in the server)
Check the /home directory permissions. It should be
drwxr-xr-x. 9 root root 113 Jun 28 22:57 home
and then your home directory detail:
drwxr----- 5 user group 124 May 18 17:00 User
drwx------ 2 user group 29 May 18 12:05 .ssh
-rw------- 1 user group 2235 Jun 28 23:09 authorized_keys
My error messages in logs
/var/log/secure > sshd[22565]: error: Received disconnect from X.X.X.X: 14: No supported authentication methods available [preauth]
On client side
ssh user#X.X.X.X
Permission denied (publickey).
ssh -vvv user#X.X.X.X
...
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
On server side
service sshd stop
run sshd debug mode:
/usr/sbin/sshd -ddd
...
debug1: trying public key file /home/USER/.ssh/authorized_keys
debug1: Could not open authorized keys '/home/USER/.ssh/authorized_keys': Permission denied
...
A couple ideas to check:
Can you cat authorized_keys? What does the file look like?
Is your sshd configured to allow root login? This is generally frowned upon,
Are you doing it as root or as a sudoer?
Don't do chmod on ~/.ssh/.... Try to write the exact path: /root/.ssh/..., since sometimes (when using su etc), the ~ can be setup incorrectly. Check and post the permissions again for the full path without using ~ in the command.
Once you are absolutely sure the permissions are OK, check if your sshd is actually running under user root: ps -A u | grep sshd.
A couple of things to double-check:
Are you sure you copied the PUBLIC key to the authorized_keys, not
the private key? :-)
Do cat -tv authorized_keys. Any ^M characters at the end of each line? Do a dos2unix on authorized_keys
Did you restart the ssh daemon after making
configuration changes?
I encountered this same issue and got it solved by changing both .ssh and authorized_keys's owner at the same time:
chown MyUsername:Myusername .ssh
chown MyUsername:Myusername .ssh/authorized_keys
Thanks to #niclaslindgren.
And BTW, it's no matter with whether there is ^M in authorized_keys or not, I had tested and proved it, it works with both the ways
I'm going to throw my answer in here as well since I just wasted the last hour trying to figure out a workaround for another hour I wasted previously on Azure.
This does not work:
AuthorizedKeyFiles ~/.ssh/authorized_keys
Generating server-side logs using an alternate port (i.e. /usr/sbin/sshd -ddd -p 12345) reveals the following when using the above configuration:
debug1: trying public key file /root/.ssh/authorized_keys
debug1: Could not open authorized keys '/root/.ssh/authorized_keys': Permission denied
Either of these are correct, however:
AuthorizedKeyFiles /home/%u/.ssh/authorized_keys
AuthorizedKeyFiles .ssh/authorized_keys
See also: https://www.ssh.com/ssh/authorized_keys/openssh
For me it was also changing ownership, but not just of authorized_keys but also of the .sdd directory:
chown -R user:user ./home/user/.ssd
In my case, home directories are on NFS, which means that ~/.ssh is also on NFS.
Found this answer, and indeed running the following (as root) solved the problem:
setsebool -P use_nfs_home_dirs 1
There is a set of generic steps if one has to find the reason why sshd is refusing to accept a connection or keys.
The details below are for a systemd based system but alternative systems users would be able to find their way easily.
How to debug sshd systematically?
Start watching the journal
journalctl -u sshd -f
Set sshd logging to debug mode in /etc/ssh/sshd_config
LogLevel DEBUG
Restart the daemon to let the change take effect
systemctl restart sshd
We are set on the server side.
Try the client connection now
ssh -o IdentitiesOnly=yes -v -i ~/.ssh/key_to_the_kingdom king#kingdom.gov
IdentitiesOnly disables trying other than the identity specified.
-v to increase the client verbosity so one can see if the client is doing what is expected. (Is able to find and use the key on the client system, is able to negotiate the encryption algorithm, etc.)
(Not posting an example for the client.)
On the server (kingdom.gov in our example), we should see something like the following in the debug mode log:
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: userauth-request for user king service ssh-connection method none [preauth]
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: attempt 0 failures 0 [preauth]
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: PAM: initializing for "king"
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: PAM: setting PAM_RHOST to "75.73.78.71"
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: PAM: setting PAM_TTY to "ssh"
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: userauth-request for user king service ssh-connection method publickey [preauth]
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: attempt 1 failures 0 [preauth]
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: userauth_pubkey: test pkalg rsa-sha2-512 pkblob RSA SHA256:0hjXPXkM8d91W2D8bg3fcapifm5QJd7QV9wwOEMU1 [preauth]
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: temporarily_use_uid: 112233/10 (e=0/0)
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: trying public key file /home/king/.ssh/authorized_keys
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: Could not open authorized keys '/home/king/.ssh/authorized_keys': Permission denied
Jul 14 12:46:39 kingdom.gov sshd[4665]: debug1: restore_uid: 0/0
Jul 14 12:46:39 kingdom.gov sshd[4665]: Failed publickey for king from 83.69.65.84 port 52756 ssh2: RSA SHA256:0hjXPXkM8d91W2D8bg3fcapifm5QJd7QV9wwOEMU1
In my case, the problem was in SELinux not allowing to use authorized_keys stored in the NFS home directory.
You may be asking: How can I check the permissions? What is the identity sshd uses to access the files?
Look at temporarily_use_uid: 112233/10 in the log above. There should be correct UID and primary GID for the user.
In my case, these values were taken from the name service (LDAP) and were as expected.
If the client user identity is incorrect, look into the name service configuration and resolve this issue first.
The directory and file ownership and permissions were as expected (at least u=x for ~ and ~/.ssh directories, at least u=r for authorized_keys, if owned by the user).
It was clear the reason must be in something like SELinux.
Let's check it:
getsebool use_nfs_home_dirs
use_nfs_home_dirs --> off
For that case, the answer by Nadav Aharoni resolves the problem.
setsebool -P use_nfs_home_dirs 1
Cleanup
Restore LogLevel DEBUG in sshd_config to the previous value. (Or comment it out to restore the default.)
systemctl restart sshd

apache cannot access public_html on CIFS

I have my computer on network, and whole homedir is mounted at login with CIFS. When I access http://localhost everything works fine, but when I access http://localhost/~user it fails.
# cat /etc/mtab
.....
//192.168.1.5/user/ /home/user cifs rw,mand 0 0
ls -l
...
drwxrwxrwx 37 user domain users 0 2011-12-22 09:12 public_html
The browser say:
Forbidden
You don't have permission to access /~lluisforns on this server.
And apache say
cat /var/log/apache2/error.log
[Thu Dec 22 18:19:09 2011] [error] [client 127.0.0.1] (13)Permission denied: access to /~lluisforns denied
Any idea?
Had the same issue, and it turned out to be an SELinux thing: SELinux has a setting that prevents httpd (apache) to follow CIFS links.
To see if you have this issue:
getsebool -a | grep httpd
you should see httpd_use_cifs --> on. if not, your in luck - this is your problem.
To fix:
setsebool httpd_use_cifs on
You may also decide to disable SELinux altogether (assuming you know the risk) - here is a link to one relevant page