Sometimes users require SFTP access to their File storage on our Linx Cloud servers. Here’s the steps to set it up from a Server Management point of view.
- Remote Desktop into the machine and access Powershell
C:\> powershell
- Install Open-SSH
Get-Service -Name “sshd” | Set-Service -Startup “Automatic” -PassThru | Start-Service -PassThru
- Change the Port number to what-ever you want to use, in this case Port 2223
(Get-Content “C:\ProgramData\ssh\sshd_config”).replace(“#Port 22”, “Port 2223”) | Set-Content “C:\ProgramData\ssh\sshd_config”
Restart-Service “sshd”
- Check the port to see if SSH is running
Get-NetTCPConnection -LocalPort 2223 | select Local*, State,
@{n="ProcessName";e={(Get-Process -Id $_.OwningProcess).ProcessName}},
@{n=“ProcessPath”;e={(Get-Process -Id $_.OwningProcess).Path}} | ft -Auto
- Create a new Group to assign users to
New-LocalGroup -Name “SFTPUsers”
- Set up a new user
$Password = Read-Host -AsSecureString
$params = @{
Name = ‘ftpuser’
Password = $Password
FullName = ‘FTPUser’
Description = ‘FTPUser’
}
New-LocalUser @params
- Assign user to new group
Add-LocalGroupMember -Group SFTPUsers -Member ftpuser
- Go to your SSH folder and open the ssh_config file with Notepad
cd \
cd ProgramData\ssh
Notepad.exe ssh_config
- Add the root folder you want to use for SFTP into the config. Any place is fine
ChrootDirectory “F:\MyDrive”
- Allow users to log in with passwords, by uncommenting this line
PasswordAuthentication yes
- Add the newly created Group to access SFTP
AllowGroups yourserverlocalname\SFTPUsers
- Save the file and close Notepad. Restart SSH
Restart-Service “sshd”
-
Go to the root folder where the folder that we are using as SFTP Home is located. In our case F:
-
Set the permissions for our newly created Group to have READ rights on this folder
$ACL = Get-ACL -Path “MyDrive”
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(“yourserverlocalname\SFTPUsers”,“Read”,“Allow”)
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl -Path “MyDrive”
(Get-ACL -Path “MyDrive”).Access | Format-Table IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -AutoSize
- Set the permissions for our new Group to NOT have Write access. Thus we’re giving Read-Only access:
$ACL = Get-ACL -Path “MyDrive”
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(“yourserverlocalname\SFTPUsers”,“Write”,“Deny”)
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl -Path “MyDrive”
(Get-ACL -Path “MyDrive”).Access | Format-Table IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -AutoSize
- Try with an SFTP client, like Linx or FileZilla to log into the our new SFT server. Should work.