1

I have been stuck with this issue all afternoon and I don't know what is going on. The reason why I need to use the sftp command is because I am using it in a shell script. If there is another program I could use that comes with CentOS 7 that allows me to download a file using SFTP then please enlighten me.

EDIT 1

SFTP clients used: WinSCP and PSFTP.

Tested this from different computers both running on the same network and from the internet (used only IP addresses here). This works as expected from the same computer (used localhost and loopback address).

Firewalld service is stopped, and no proxy is being used or has been configured at any time.

The error I am getting is (using sftp -vvv sftp@hostname):

debug1: connect to ipaddress port 22: Connection timed out
ssh: connect to host ipaddress port 22: Connection timed out
Couldn't read packet: Connection reset by peer

My sshd_config file (server-side):

#       $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
GSSAPIAuthentication no
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 60
#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    internal-sftp

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
Match User sftp
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /home/sftp
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no

Code used to create the user:

mkdir -p /home/sftp
chown root /home/sftp
chmod 755 -R /home/sftp
useradd -d /home/sftp -r sftp
usermod -s /sbin/nologin sftp
echo "password" | passwd --stdin sftp

I have not touched the sshd_config file from the clients, so I guess it is just the defaults from installation (in my implementation I cannot change those configuration files).

  • does the user you are using to invoke sftp have rightrs on the box you are trying to get the files? – vfbsilva Dec 29 '17 at 16:02
  • 1
    What "other sftp clients" are you using? Are you running them on the same machine as the sftp? – Martin Prikryl Dec 29 '17 at 16:11
  • 1
    I will edit my question to add the code I used to create the user @vfbsilva. – Juanse Albuja Dec 29 '17 at 16:45
  • please clarify, is the sshd_config for the server you are going to? please also post the ssh_config for your client system, as that is the client config. – John Dec 29 '17 at 16:47
  • 1
    @JuanseAlbuja Thanks. Though for this specific problem, testing from another machine is irrelevant. – Martin Prikryl Dec 29 '17 at 16:50
0

Is your WinSCP configured to use any kind of a proxy? PSFTP can use a proxy only if you save a session configuration (including the proxy settings) using PuTTY configuration dialog and then use psftp -load <name of saved session>.

Or is it possible that one of your SFTP clients attempts to use IPv4 and the other IPv6, and only one of those is allowed? (i.e. if you're using a hostname with WinSCP, it might be looking up both IPv6 and IPv4 addresses and using the IPv6 address.)

  • Proxy has not been configured nor pointed to on any scenario. Will update question when I have access to my computer. Thanks for trying and happy new year! – Juanse Albuja Jan 1 '18 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.