How can I create a user account that is only allowed to use SCP for file transfers and cannot log in interactively via SSH?

Hey, We need to create a user account that is only allowed to use SCP for file transfers and cannot use SSH to log in or open a shell session.

Thanks :folded_hands:

Server Side

Add SCP onl user and group on te server as shown below.

# groupadd scponly
# useradd -G scponly -d /recv -M scpuser
# echo redhat | passwd --stdin scpuser

Create a dedicated directory specifically for use with SCP.

# mkdir /recv
# chmod 777 /recv

Add the configuration shown below to the sshd_config file and then restart the SSH service.

# vim /etc/ssh/sshd_config 
Match Group scponly
        ForceCommand /usr/bin/scp -t  /recv
# /etc/init.d/sshd restart

Client Side

Create a test file and then use the SCP‑only user to copy that file to the server with scp.

# echo "testfile" > test.txt
# scp test.txt scpuser@**Server**:/recv

Check whether the SCP‑only user is able to log in via SSH.

# ssh scpuser@**Server**

As a result, you will see the following output:

scp: protocol error: unexpected <newline>
Connection to **Server** closed.

Verify the SCP‑transferred file on the server to confirm it was copied correctly.

# cat /recv/test.txt 
testfile

Have a good day. Let me know if you need more help.

:waving_hand: