New sftp hosted on centos7

Issues related to applications and software problems
Post Reply
mstrommenJevs
Posts: 4
Joined: 2015/06/19 15:34:33

New sftp hosted on centos7

Post by mstrommenJevs » 2015/06/19 15:43:46

I am configuring an sftp server to allow a vendor to send us a file nightly. I am fairly new to centos so appologies if I am missing something very obvious.
I am trying to follow the guide viewtopic.php?f=17&t=46666.

I have created my user and made him a member of the sftponly group. I have loaded a public key I generated in /usr/sftp/i-sftp/kronos/.ssh/authorized_keys.

When I uncomment:

Code: Select all

#RSAAuthentication yes
#PubkeyAuthentication yes
I am able to sftp connect as root using my rsa key

When I attempt to connect as kronos I get:
Disconnected: No supported authentication methods available (server sent: publickey,gssapi-keyex,gssapi-with-mic)
I feel like it might be a permissions issue for the kronos use accessing the authorized_keys.
I have tried giving kronos ownership of the .ssh directory and setting chmod 0422 for authorized_keys.

I am not sure where else to look at this point. Thanks for looking at my issue!

My sshd_config:

Code: Select all

#       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 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:/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 override the
# default value.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# The default requires 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
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Ciphers and keying
#RekeyLimit default none

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
 AuthorizedKeysFile     .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser 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 yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users 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'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox          # Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# 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

# override default of no subsystems
#Subsystem      sftp    /usr/libexec/openssh/sftp-server
Subsystem       sftp    internal-sftp

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

Match Group sftponly
        ChrootDirectory /mnt/win
        ForceCommand internal-sftp -l VERBOSE
        X11Forwarding no
        GSSAPIAuthentication yes
        AllowTCPForwarding no
        PasswordAuthentication no
        PubkeyAuthentication yes
        AuthorizedKeysFile     /usr/sftp/i-sftp/kronos/.ssh/authorized_keys

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: New sftp hosted on centos7

Post by TrevorH » 2015/06/19 18:43:55

Look in your logs for errors - specifically in /var/log/messages and /var/log/secure.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

mstrommenJevs
Posts: 4
Joined: 2015/06/19 15:34:33

Re: New sftp hosted on centos7

Post by mstrommenJevs » 2015/06/22 14:06:47

Thank you for reply!

in /var/log/secure I can see the following:

Code: Select all

Jun 22 09:42:47 FTPLinux sshd[14460]: error: Received disconnect from 192.168.1.138: 14: No supported authentication methods available [preauth]
Jun 22 09:42:52 FTPLinux sshd[14462]: error: Received disconnect from 192.168.1.138: 14: No supported authentication methods available [preauth]
/var/log/messages is filled with, although they don't look related to me:

Code: Select all

Jun 22 06:01:01 FTPLinux systemd: Created slice user-0.slice.
Jun 22 06:01:01 FTPLinux systemd: Starting Session 68 of user root.
Jun 22 06:01:01 FTPLinux systemd: Started Session 68 of user root.
Jun 22 07:01:01 FTPLinux systemd: Created slice user-0.slice.
Jun 22 07:01:01 FTPLinux systemd: Starting Session 69 of user root.
Jun 22 07:01:01 FTPLinux systemd: Started Session 69 of user root.
Jun 22 08:01:01 FTPLinux systemd: Created slice user-0.slice.
Jun 22 08:01:01 FTPLinux systemd: Starting Session 70 of user root.
Jun 22 08:01:01 FTPLinux systemd: Started Session 70 of user root.
Jun 22 09:01:01 FTPLinux systemd: Created slice user-0.slice.
Jun 22 09:01:01 FTPLinux systemd: Starting Session 71 of user root.
Jun 22 09:01:01 FTPLinux systemd: Started Session 71 of user root.
Jun 22 09:42:42 FTPLinux systemd: Created slice user-0.slice.
Jun 22 09:42:42 FTPLinux systemd: Starting Session 72 of user root.
Jun 22 09:42:42 FTPLinux systemd: Started Session 72 of user root.
Jun 22 09:42:42 FTPLinux systemd-logind: New session 72 of user root.
I Googling tells me it might be a problem with the permissions of authorized_keys
I tried 644.
Currently it's 600.

Code: Select all

[root@FTPLinux .ssh]# ls -l authorized_keys
-rw-------. 1 kronos sftponly 398 Jun 19 10:34 authorized_keys

User avatar
AlanBartlett
Forum Moderator
Posts: 9345
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: New sftp hosted on centos7

Post by AlanBartlett » 2015/06/22 14:20:57

mstrommenJevs wrote:Googling tells me it might be a problem with the permissions of authorized_keys
I tried 644.
Currently it's 600.

Code: Select all

[root@FTPLinux .ssh]# ls -l authorized_keys
-rw-------. 1 kronos sftponly 398 Jun 19 10:34 authorized_keys[/quote]
The user's [b].ssh[/b] directory itself must be mode [b]0700[/b] and all the files contained therein must be mode [b]0600[/b].
Image 100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

mstrommenJevs
Posts: 4
Joined: 2015/06/19 15:34:33

Re: New sftp hosted on centos7

Post by mstrommenJevs » 2015/06/22 16:31:43

Code: Select all

[root@FTPLinux win]# ls -ld /usr/sftp/i-sftp/kronos/.ssh
drwx------. 2 kronos sftponly 28 Jun 19 11:04 /usr/sftp/i-sftp/kronos/.ssh
[root@FTPLinux win]# ls -l /usr/sftp/i-sftp/kronos/.ssh
total 4
-rw-------. 1 kronos sftponly 398 Jun 19 10:34 authorized_keys
[root@FTPLinux win]#
Does that look right? My user is kronos.

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: New sftp hosted on centos7

Post by MartinR » 2015/06/22 16:35:35

That's a slight simplification. See the man page ssh(1) which says that there is no requirement to keep ~/.ssh secret, but then recommends 0700. The key files must be private or they will be ignored. The public versions (eg id_dsa.pub) however can be readable by anyone; personally I'd make copies elsewhere if I wanted anyone else to see them. Authorized_keys is recommended 0600, but not enforced and known_hosts probably ought not to be writeable by others.

mstrommenJevs
Posts: 4
Joined: 2015/06/19 15:34:33

Re: New sftp hosted on centos7

Post by mstrommenJevs » 2015/06/22 16:58:43

MartinR wrote:That's a slight simplification. See the man page ssh(1) which says that there is no requirement to keep ~/.ssh secret, but then recommends 0700. The key files must be private or they will be ignored. The public versions (eg id_dsa.pub) however can be readable by anyone; personally I'd make copies elsewhere if I wanted anyone else to see them. Authorized_keys is recommended 0600, but not enforced and known_hosts probably ought not to be writeable by others.

I am not really sure what to make of this, are you suggesting a change?

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: New sftp hosted on centos7

Post by MartinR » 2015/06/22 20:31:34

Unless you have a good reason to change I would stick with Alan's recommendation, particularly it it works. It's a simplification, not wrong.

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: New sftp hosted on centos7

Post by MartinR » 2015/06/22 22:38:47

I've been reviewing the thread so far. The first thing I would suggest is that you make sure that ssh works, sftp should then be sorted out. Just use a command like

Code: Select all

$ ssh [<user>@]<server> pwd
and if you get the home directory returned all is well.

The full exchange consists of two parts:
1) Is the client happy that it is talking to the right server?
a) The client uses a known_hosts file to get the public key of the server. It uses this to interrogate the server.
b) The server uses its machine private key to decypher the host request and confirms its identity.
2) Is the client happy the user is authorised?
a) The client uses a private key to encypher a message announcing itself.
b) The server uses authorized_keys to decypher the message and sends back an acceptance.
The client can now send a command.

The above is a simplification, the exchange also sets up some additional cryptographic stuff to ensure the channel isn't snooped on, but it will do for the moment.

Since you say that you can ssh to the server from the root account, we can assume that part 1 is working. You now need to check the following:
* Is the client user's .ssh directory secure?
* Is the server user's .ssh directory secure?
* Is there a valid private key in the client user's account, and is it secure?
* Is the public key corresponding to this client user in the authorized_keys file of the server user? Is the file secure?

Try the command above. If it fails, please try again using -v (verbose) and post the results after suitable redaction. You can check for messages in /var/log/secure and /var/log/messages by grep'ping for ssh, not FTP.

Post Reply