Forcing UID on Files/Dirs Created with SFTP?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Forcing UID on Files/Dirs Created with SFTP?
# 1  
Old 05-27-2008
Forcing UID on Files/Dirs Created with SFTP?

I have a situation where I have to provide Windows based users with access to specific files and directories on a *nix web mail server. The users cannot use the CLI, so SSH is out. They've previously used a product called Webdrive to access *nix boxes via SFTP.

The files and dirs they need read/write access to are have user:group set to an account with an autogenerated and unknown password, so I can't just connect them with the application user's credentials. I also will not give them 'root' access. Instead I created a user account for them and added that account to the application user's group. This allows them to log in and work with limited access, which is fine.

However, the problem that remains is that all files and dirs they create are for their own user:group settings. The end result is that every time they make a change, I have to ssh in and 'chown -R user:group /path/to/appfiles'. In Samba (which we can't use for security reasons) there is a way to force the logged in user to create files as a different user:group as specified by the admin. I was wondering if there was any way to do this with SFTP?
# 2  
Old 05-27-2008
chgrp chown both work as commands in sftp.

We've got WinSCP. Wrote tiny vbscript frontends that live on each PC. Users pick a file from a local list to send, or pick a file from a remote list of files to copy back to local. They are all logging on as the exact same user. All sftp's support chgrp and chmod as long as they are seen in the chroot jail on the remote side. Yoiu can add those to the winscp dialog in vbscript.

This is all in the scripting.
# 3  
Old 05-27-2008
Thanks. That would work well if they didn't require Webdrive. I tried pointing them to WinSCP before, but they rejected it since it was too hard to use. Web drive just makes the SFTP connection look like a mapped drive in Windows Explorer. I don't have much of a choice since they kind of run the show with web stuff and I'm merely supporting them. (I have to run 'find' every time they connect so that I can remove all the Thumbs.db files that Explorer creates over the SFTP session. Should probably ask the Windows admin to disable thumbnails...) Thanks again, for the suggestion.
# 4  
Old 05-27-2008
Not sure if this is of any benifit, but try Bitvise Tunneller - it's a free client and IMHO worth it's weight in gold!

Tunnelier: SSH Terminal, Tunneling and File Transfer Client

Tunnelier is a friendly and flexible SSH client for Windows which includes state of the art terminal emulation, graphical as well as command-line SFTP support, an FTP-to-SFTP bridge, powerful tunneling features including dynamic port forwarding through integrated proxy, and also remote administration for our SSH server, WinSSHD.

Tunnelier is free for individual use.

And no, I don't get any royalties for the plug Smilie (though I wish)

Cheers,
Cameron
# 5  
Old 05-28-2008
Cameron. Thanks for the suggestion. That looks a lot nicer than PuTTY and WinSCP and it's one client. I'm sure I'll find uses for that. Smilie In this particular situation I'm stuck though... The users refuse to consider anything but Webdrive and it doesn't appear to have any way to do chown or chgrp. I think I might just set up an ssh login for them with a menu instead of a shell and have them select "Post Upload Cleanup" as an option to do the chown and chgrp in the background.
# 6  
Old 05-28-2008
Second stage process - that's an idea.
Incidently, I've posted the basic help for sftpc so you can peruse.
And why could you not change the vb script to execute the sftpc instead ??
Have highlighted points that may be of interest for yourself (I'm taking a guess) ... Smilie
Code:
C:\>sftpc /?
Bitvise Tunnelier 4.16 - sftpc, a command line SFTP client.
Copyright (C) 2000-2006 by Bitvise Limited.
Portions Copyright (C) 1995-2003 by Wei Dai.

USAGE:
sftpc [username@]host[:port] OR -profile=file [-host=host] [-port=port] [-spn=SPN] [-sspi=y|n] [-dlg=y|n]
      [-user=username] [-gka] [-gma [-krb OR -ntlm]] [-pk=slot [-pp=passphrase]] [-pw=password] [-kbdi
      [-sub=submethods]]
      [-cmd=commands OR -cmdFile=file [-ce]] [-bg]
      [-encr=list] [-mac=list] [-cmpr=list] [-dhkex=list] [-hkey=list] [-ka=y|n] [-kre=y|n]
      [-unat=y|n]
      [-noRegistry]
      [-proxy=y|n [-proxyType=type] -proxyServer=server [-proxyPort=port] [-proxyUsername=username
      [-proxyPassword=password]] [-proxyResolveLocally]]
      [-hostKeyMD5=MD5-fingerprint] [-hostKeyBB=Bubble-Babble] [-hostKeyFile=file]
      [-keypairFile=file [-keypairPassphrase=passphrase]]
      [-traceLevel=level [-traceFile=file]]

PARAMETERS:
-profile=file
  Load connect parameters from the specified Tunnelier profile. Server host, port, SPN, SSPI, username, initial
  authentication method, algorithms, keep alive and re-exchange settings are loaded. If a command line parameter is
  additionally specified for any of these, it overrides the corresponding profile setting.
-host=host
  The server host to connect to overriding the already set host.
-port=port
  The port on server host to connect to overriding the already set port.
-spn=SPN
  If specified, Tunnelier will use the value of this parameter as the service principal name during Kerberos
  authentication. If not specified, Tunnelier will use a default, but possibly incorrect, SPN based on the SSH server's
  host name.
-sspi=y|n
  SSPI/Kerberos 5 host authentication - disabled by default, but can also be disabled explicitly to override profile
  setting.
-dlg=y|n
  Permit access delegation - disabled by default, but can also be disabled explicitly to override profile setting. For
  use only with SSPI/Kerberos 5 host authentication.
-user=username
  The username to login with overriding the already set username.
-gka
  Log in using the gssapi-keyex method. Available only when SSPI/Kerberos 5 host authentication has been performed. Can
  also be combined with other authentication methods, in which case gssapi-keyex is attempted first.
-gma
  Log in using the gssapi-with-mic method. Can also be combined with other authentication methods, in which case
  gssapi-with-mic is attempted after gssapi-keyex.
-krb
  Use gssapi-with-mic with the Kerberos 5 mechanism only.
-ntlm
  Use gssapi-with-mic with the NTLM mechanism only.
-pk=slot
  Log in using the publickey method, with the keypair at the specified slot. Can also be combined with other
  authentication methods, in which case publickey is attempted after gssapi-with-mic.
-pp=passphrase
  A passphrase for the keypair specified with -pk.
-pw=password
  Log in with the specified password. Can also be combined with other authentication methods, in which case the password
  is attempted after the publickey method.
-kbdi
  Log in with the keyboard-interactive method. Can also be combined with other authentication methods, in which case the
  keyboard-interactive method is attempted last.
-sub=submethods
  Optional submethods for keyboard-interactive.
-cmd=commands
  Establish the session, run semicolon-separated SFTP commands, and exit. There is no prompt for additional user input.
  All occurences of '"' that are part of the parameter value must be replaced with '\"', e.g. "-cmd=get \"file
  name.txt\"". See also Return Codes.
-cmdFile=file
  Like -cmd but load commands from the specified textual file, one per line. In the file, there is no need for escaping
  the quote character as is necessary with -cmd. The file will be interpreted as Unicode or UTF-8 if the respective BOM
  marker is present. Otherwise, the ANSI code page will be used. Empty lines and lines containing only whitespace are
  ignored.
-ce
  Continue on error: if multiple commands are specified using the -cmd or -cmdFile parameter and one fails, continue
  with subsequent commands. By default, execution will stop at the first failed command. The return code for the first
  failed command is returned in all cases, or 0 if all commands succeed.
-bg
  Start downloads and uploads in background by default.
-encr=list
  Comma-separated priority list of session encryption algorithms. If not specified, the following algorithm list is
  assumed: aes256-cbc,twofish256-cbc,twofish-cbc,aes128-cbc,twofish128-cbc,blowfish-cbc,3des-cbc,arcfour,cast128-cbc.
-mac=list
  Comma-separated priority list of session MAC algorithms. If not specified, the following algorithm list is assumed:
  hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96.
-cmpr=list
  Comma-separated priority list of session compression algorithms. If not specified, the following algorithm list is
  assumed: none.
-dhkex=list
  Comma-separated priority list of DH key exchange algorithms. If not specified, the following algorithm list is
  assumed: diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1, plus any GSSAPI
  key exchange methods if -sspi was specified.
-hkey=list
  Comma-separated priority list of host key algorithms. If not specified, the following algorithm list is assumed:
  ssh-dss,ssh-rsa.
-ka
  Keep-alive / broken session detection - enabled by default, but can also be enabled explicitly to override profile.
-kre
  Key re-exchange - enabled by default, but can also be enabled explicitly to override profile.
-unat=y|n
  Use unattended mode to prevent any user interaction by the SSH session - in particular, host key verification and user
  authentication. Unattended mode is used by default only with the -cmd or -cmdFile parameters
-noRegistry
  Do not load settings from or store them to Windows registry. Use of global client proxy settings, host key database,
  and user keypair database is prevented.
-proxy=y|n
  Use a proxy server, overrides global client proxy settings.
-proxyType=type
  The type of proxy server to use. 'SOCKS4', 'SOCK5', and 'HTTP' proxy types are supported. 'SOCKS4' is set by default.
-proxyServer=server
  The IP address or DNS name of the proxy server.
-proxyPort=port
  The proxy server port, 1080 by default.
-proxyUsername=username
  The proxy server username (SOCKS5 and HTTP only).
-proxyPassword=password
  The proxy server password (SOCKS5 and HTTP only).
-proxyResolveLocally
  Resolve a DNS name locally before passing it to the proxy when this flag is used.
-hostKeyMD5=MD5-fingerprint
  A MD5 fingerprint of the host key to accept, used additionally to global client host key database
-hostKeyBB=Bubble-Babble
  A Bubble-Babble of the host key to accept, used additionally to global client host key database
-hostKeyFile=file
  A file containing host keys to accept, used additionally to global client host key database
-keypairFile=file
  A file containing a private key for authentication; overrides keys in global client user keypair database.
-keypairPassphrase=passphrase
  Provide a passphrase for the keypair specified with the -keypairFile parameter. Passphrase must always be present when
  an OpenSSH encoded and passphrase protected keypair is specified.
-traceLevel=level
  An integer number in the range 0-3, default 0 (no tracing). If non-zero, low-level session information such as packets
  sent and received will be logged. A higher number means more information will be recorded. At trace level 3, all data
  sent across the SSH connection will be logged.
-traceFile=file
  If a non-zero trace level is specified, a textual file to write trace messages to. If not specified, trace messages
  are written to standard output. When writing trace messages to standard output, they will be cut off at 200
  characters. When tracing, a trace file should usually be used.

EXAMPLES:
sftpc myserver
  Logs into 'myserver' with the account name of the current Windows user as the username. Will prompt to choose an
  authentication method when connected.
sftpc someuser@myserver
  Logs into 'myserver' as 'someuser'; will prompt to choose an authentication method when connected.
sftpc someuser@myserver:9222 -bg
  Logs into 'myserver' on port 9222 as 'someuser'. Transfers will be started in background by default, i.e. if you
  execute "get x.txt", this will be treated as "get x.txt -bg". Transfers can still be started in foreground using the
  '-fg' flag, e.g. "get x.txt -fg". See "help get", "help put".
sftpc myusername@myserver -pw=mypassword -cmd="cd /temp; get *; put \"a b c\""
  With these parameters, sftpc will log into 'myserver' as 'myusername' with password 'mypassword', and it will proceed
  to execute commands as follows:
    cd /temp
    get *
    put "a b c"
  Each of these commands is executed in order; if one fails (e.g. if the /temp directory does not exist), the rest will
  not be executed.
sftpc myusername@myserver -pk=1 -ce -cmd="cd /temp; get *; put x.txt"
  This is a similar example to the one above, but the additional -ce parameter will cause execution to continue even if
  an error occurs, and the -pk=1 parameter will cause the public key in slot 1 to be used instead of a plain password.

RETURN CODES:
   0  Success
   1  Unknown failure
   2  Usage error
 100  SSH session failure
 101  Failure connecting to server
 102  SSH host authentication failure
 103  SSH user authentication failure
 200  SFTP session failure
 201  SFTP channel failure
 202  SFTP request rejected
 203  SFTP initialization failure
 204  SFTP protocol failure
 205  SFTP session closed by server
1000  Failed -cmd command #1
1001  Failed -cmd command #2
 ...  ...

To more easily read the above help, try:
  sftpc -help-usage    (display usage)
  sftpc -help | more   (displays help page by page)
  sftpc -help > h.txt  (creates a text file you can open e.g. with Notepad)
  sftpc -help-params   (display parameters help)
  sftpc -help-<param>  (display help for a particular parameter)
  sftpc -help-examples (display examples)
  sftpc -help-codes    (display return codes)

Anyways, hope it all works out - post back to let us know. Smilie

Cheers,
Cameron

Last edited by Cameron; 05-28-2008 at 11:24 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a string in files in all dir and sub dirs

Hello, I need to replace xml version='1.1' with xml version='1.0' in all xml files under /app/jenkins/ in all dir and sub dirs in my CentOS VM, I tried below command but it didn't help, looks like I'm missing a character somewhere. grep -rl "xml version='1.1'" . | xargs sed -i 's/"xml... (2 Replies)
Discussion started by: mahesh Madpathi
2 Replies

2. Shell Programming and Scripting

Moving files into dirs corresponding to dates

I am trying to find a way to move files into corresponding date files. i=0 while read line do array="$line" (( i++ )) done < <(ls) cd $(echo ${array}) echo ${array}} pwd #cd "$(array}" ] || mkdir 2015 cd "2015" ] || mkdir 02-February ] || mkdir 03-March ] || mkdir... (10 Replies)
Discussion started by: newbie2010
10 Replies

3. Debian

Problem with files/dirs deletion

Hi, The other day i installed a PHP based CMS (modx) on my shell account and noticed that i couldn't delete any of files/dirs it created after. Also, i noticed that all that stuff is owned by username-www instead of username. I tried chown, chmod and using a PHP script to do the same wti... (4 Replies)
Discussion started by: pentago
4 Replies

4. Shell Programming and Scripting

AWK help print dirs with files in it

Hi, I'm writing some start of day checks for my work. I want to check some dirs for files that have been created longer than 10 mins ago and not been transfered. I've already used a find command to write a list of files that meet this criteria to a log called sod.log i.e. ... (1 Reply)
Discussion started by: elcounto
1 Replies

5. Shell Programming and Scripting

sftp - get newly created files on incremental basis

Hi, We have a sftp server which creates files daily and keeps 6 months of files on the server. We are creating a daily job to get the files and load into database. My problem is "how to get ONLY those files which got created after my last get". Let me provide some more details to it. Below... (15 Replies)
Discussion started by: ravi.videla
15 Replies

6. UNIX Desktop Questions & Answers

limit number of sub-dirs searched for files

using: find . -type f -print|xargs -li "string", how do I limit the dated directories (2010-7-14, 2010-7-13,etc.) to just 2009 & 2010 years of directories to search. We go back to 2004 in our archives, way too many files. (3 Replies)
Discussion started by: MJThom713
3 Replies

7. Shell Programming and Scripting

Have absolute path for files in different dirs

Hi everybody. I need a command to print the absolute path of files which name starts always with a pattern (MOD03), independently on where they are in the filesystem. I have tryedls -ld ${INPUTPREFIX}/*/*/* | grep MOD03 | awk '{ print $8 }'but I have to use "/*/*/*" in this case to have the... (5 Replies)
Discussion started by: canduc17
5 Replies

8. Shell Programming and Scripting

Find most recent files in dirs and tar them up?

Hey all.. This should be simple but stoopid here can't get head around it! I have many directories, say 100 each with many files inside. I need a script to traverse through the dirs, find most recent file in each dir and add it to a tar file. I can find the files with something like for... (1 Reply)
Discussion started by: bobdung
1 Replies

9. Shell Programming and Scripting

script find files in two dirs HELP

I have a directory which is /home/mark/files/ , inside this particular I have a bunch of filles (see examples below) TST_SHU_00014460_20090302.txt TST_SHU_00016047_20090302.txt TST_SHU_00007838_20090303.txt TST_SHU_00056485_20090303.txt TST_SHU_00014460_20090303.txt... (2 Replies)
Discussion started by: fierusbentus
2 Replies

10. UNIX for Dummies Questions & Answers

I need to ls all files in 4-6 deep dirs

I need to print to file , a listing of all files below a certain directory. Example: I need to print to file a listing of all files below the etc dir (including the subdirectories) with their full path. Any ideas on how to do this with one command. Or is this something I need to do on all... (4 Replies)
Discussion started by: gforty
4 Replies
Login or Register to Ask a Question