Skip to main content

Setting up an SFTP Account with RSA Key Access

Sometimes you need to setup an SFTP account with a user name and password... Other times you're asked to provide a RSA key for authentication. I'll be going over the setup of an account using RSA authentication. For this setup, I have a CentOS Linux box sitting in the DMZ that has been hooked into Active Directory (AD) using Centrify (more about Centrify HERE). I have Centrify scoped to only allow logins to users in two groups within AD, "Domain Admins" and "SFTP-Only-Users". The configuration/setup of Centrify is beyond the scope of this, but any documentation for setting up group based access can be found by searching through their KB articles. I also use Centrify enabled Samba to share the folders to the internal systems. This makes it easy to setup a task to move files from the SFTP directories to an internal file server, or to grant access to your internal users.

Setting up the user account 

With that said, the user account is created in AD, and assigned to the appropriate groups. The SFTP Users group for access, and a specific group for access to the folders we'll create in a moment. The purpose of assigning a group to the IN and OUT folders so you could set up a task to have the file moved to an internal file server, or provide your users access to the folders from an internal system.

Setting up the SFTP Directories

So, we'll make a total of three directories, the home directory, an IN and an OUT. From there, we'll set the permissions so that the SFTP user is chrooted to the IN and OUT directory.

As root, issue the following (replace 'UserName' and 'GroupName' with the AD user and group needed for access):
mkdir -p /home/[UserName]/{IN,OUT}
chown [UserName].[GroupName] /home/[UserName]/{IN,OUT]
chmod 2755 /home/[UserName]
chmod 770 /home/[UserName]/{input,output}


Setting up Samba

Now, whether you're a nut like me and use Centrify enabled Samba or the normal Samba, this should be a similar process. You'll be editing the 'smb.conf' file to add the necessary information to share the IN and OUT directories created above.
sudo vi /etc/samba/smb.conf
Add the following to the end of the config file:
[ShareName-IN]
path = /home/[UserName]/IN
public = no
valid usrs = +DOMAIN\[GroupName]
write list = +DOMAIN\[GroupName]
writeable = yes
create mask = 770
directory mask - 2770
Do the same for the OUT directory, but replace IN with OUT (obviously...I hope...). Save the file and restart the service.
sudo service centrifydc-samba restart
Creating RSA Keys for Access

Finally, we're to the point where we need to creat the RSA keys for authentication. At this moment, we will need to change the ownership of the /home/[UserName] directory to the user account in order to create the '.ssh' directory and keys. Then we will extract the public key and you'll share that with whomever needs access. Be cautious about who you share that file with, because it will allow access to your SFTP server.

As root, complete the following:
chown [UserName].[GroupName] /home/[UserName]
su [UserName]
cd /home/[UserName]
mkdir .ssh
cd .ssh
ssh-keygen -t rsals
cat id_rsa.pub >> authorized_keys
cd ..
chmod 700 .ssh
chmod 7000 .ssh/authorized_keys
chmod 700 .ssh/id_rsa
exit
chown root.root /home/[UserName]
Finally, you'll need to export the 'id_rsa.pub' file, rename it to what you want to identify it as, then send it off to the parties that need access to the SFTP account. All that *should* do it. Good luck.

Comments

Popular posts from this blog

Amazon and Two-Factor Auth

In this post, I'll go over setting up Two-Factor Authentication for an Amazon account. If you want more information about Two-Factor Authentication and an app recommendation, see my post on the topic HERE . If you're ready to get started, then let's go! As I've said before, this is not meant to be an in-depth guide, but more of a how-to for those that wouldn't normally think of turning on additional security settings. With that, let's get started: 1) Go to Your Account in the upper right, and fine Account Settings toward the bottom of the page: 2) Next you should see an option for Advanced Security Settings, select the Edit button: 3) On the next page you should have the open to turn on Two-Step Verification. Select the Get Started button to turn this on. 4.1) On the next page you'll have the option to either use SMS messaging or an authenticatior app. If you went through my post on 2-factor for all and installed the DUO Mobile app on your de...

Using Python for GPG/PGP File Encryption - Part 2

Previously we looked at creating keys, importing public and private keys and the overall setup of gnupg with python. This time around, we're going to take a look at file encryption. Overall the file encryption process is fairly general/easy. But it lacks in the area of scaleablilty, ie to start, you'll only be encrypting one file at a time, which can be done outside of Python with ease. The idea of going over everything in Python, is that you can setup a script to encrypt multiple files in a folder (look for that in Part 3). Assumptions; you have python, and python-gnupg installed, and a public key from someone you want to encrypt and send files to imported to your keystore home (see Part 1 for more information here. Let's get started with Python file encryption. Start off by getting into your python shell, and enter the following: >>> import os >>> import gnupg >>> gpg_home = "/path/to/keyfile/.gnupg" >>> gpg = gnupg....

Getting Samsung Dex Configured to Work with Azure DevOps Repos

Recently, I upgraded my phone to the Samsung Galaxy Note 10+... I'm a big fan of big phones (a perk to being a big guy). I've always been intrigued with the idea of using one device for everything. Well, with the Samsung Dex application that comes built into these next gen phones, it might be possible...?  As a guy that spends a lot of time working on ARM Templates and PowerShell scripts for Azure management, I was curious to see if I could get my phone, using Dex, connected to my Azure DevOps environment and start working with repos.... Well, to my surprise, I was able to, and without much pain. So, in this post, I'll run through how I got my Dex environment setup and working with Azure DevOps Repos. Getting Started With Samsung Dex open, go to the Google Play store and install Termux ( https://play.google.com/store/apps/details?id=com.termux&hl=en_US ) Once that's installed, open it! Next, we need to gift Termux with permissions to a...