Allow SFTP but not SSH

Hello,I've been looking around and searching through google but alas I cannot find an answer to this question:If I disable SSH access to an user, hrough setting the shell /usr/bin/false how would they go to connect to the server using SFTP?Regards,Damian
[290 byte] By [Damian_Finola] at [2007-11-27 3:36:55]
# 1
Oh, forgot to add, in Solaris 10.
Damian_Finola at 2007-7-12 8:40:11 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 2
Bumpty bump
Damian_Finola at 2007-7-12 8:40:11 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 3

I haven't tested this on Sol 10 but you can do what you want if you are using authorized_keys for access.

In the authorized_keys file you need to prepend (if you are using DSA keys) or append (If you are using RSA keys) the appropriate key with:

command="/usr/bin/scp -t ."

You might need to tweak that for where scp is located in your environment but that should work.

bosconeta at 2007-7-12 8:40:11 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 4
You could try using a replacement shell like scponly - http://sublimation.org/scponly/wiki/index.php/Main_Page - which only lets people run scp or sftp or whatever, without having an actual shell.
ajcosa at 2007-7-12 8:40:11 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 5

you can create a wrapper:

create /bin/sftp.sh (same perm as /bin/sh)

edit and add the following:

-

SSH_ORIGINAL_COMMAND=$2

/usr/bin/logger -p user.notice "SFTP: $SSH_CONNECTION $SSH_ORIGINAL_COMMAND"

if echo $SSH_ORIGINAL_COMMAND|egrep -e "^sftp " > /dev/null 2>&1; then

$SSH_ORIGINAL_COMMAND

elif echo $SSH_ORIGINAL_COMMAND|egrep -e "^scp " > /dev/null 2>&1; then

$SSH_ORIGINAL_COMMAND

else

/usr/bin/logger -p auth.crit "sftp-wrapper Denied $SSH_CONNECTION $SSH_ORIGINAL_COMMAND"

echo "Access denied! No logons allowed! IP logged."

fi

this will allow scp and sftp as an example.

to test create an test user and change the shell for the user to /bin/sftp

now try and su - test user

you should get: "Access denied! No logons allowed! IP logged."

you might have to do a eval "$SSH_ORIGINAL_COMMAND" if you have dirs with spaces etc. that the affected users need to upload files to.

hope this helps.

Cheers

HvRa at 2007-7-12 8:40:11 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 6

Hello.

Are the users allowed to log into the system anoter way (e.g. directly at the system's keyboard)?

If no: The two possibilities mentioned above are good!

If yes: In this case I would try to write a C program like this:

main(int argc,char **argv)

{

// Insert code that tests if the program has been started

// by SSH or any other log-in like su, xterm, popen() or

// the console log-in here.

if(is_SSH)

// Replace this by the full name of the "scponly" tool

// mentioned above.

argv[0]="scponly_directory/scponly";

else argv[0]="/bin/sh";

execv(argv[0],argv);

}

Unfortunately I do not know how to test for SSH.

Martin

Martin_Rosenaua at 2007-7-12 8:40:11 > top of Java-index,Solaris Operating System,Solaris 10 Features...