Here’s a quick example for setting up reverse SSH tunnels on clients which can be controlled via the server from anywhere. This example presumes all the client computers has some sort of unique ID/hostname, like 9001, 9002, 9003, 9004 etc. Let’s say we have 10 clients stuck behind a firewall we’d like to access.
Start the SSH server on all clients like this:
ssh -R 1xxxx:localhost:22 email@example.com // replace xxxx with this client's unique id
Now we have all our clients setup with a reversed ssh tunnel.
If we’d like to ssh into id 9003 we run the following command from the server:
ssh user@localhost -p 19003
Lets ssh into 9005 instead:
ssh user@localhost -p 19005
Replace user with a local user on the client machine.
I want to ssh into my Raspberry Pi. Local username is pi.
Step 1 – setup reverse ssh tunnel on the raspberry: ssh -R 19999:localhost:22 firstname.lastname@example.org
Step 2 – from my “it-db.com” server I run the following command: ssh pi@localhost -p 19999
/E = Copies subdirectories. Note that this option includes empty directories. If you wish to exclude empty directories, use /S.
/W:1 = Specifies the wait time between retries, in seconds. The default value of N is 30 (wait time 30 seconds).
/R:1 = Specifies the number of retries on failed copies. The default value of N is 1,000,000 (one million retries).
/XC = Excludes changed files.
/log+: = Writes the status output to the log file (appends the output to the existing log file).
Windows batch script to setup a scheduled task to run the robocopy command:
title Robocopy Backup
echo Initial configuration for automatic backup with Robocopy + Task Scheduler
echo Step 1 - setup Robocopy:
set /p src=Backup FROM dir:
set /p dest=Backup TO dir:
echo cd %userprofile%\Desktop
echo robocopy "%src%" "%dest%" /E /W:1 /R:1 /XC /log+:"robocopy_log.txt"
echo Step 2 - setup Task Scheduler:
schtasks /create /tn "Robocopy Backup" /tr "%userprofile%\robocopy.bat" /SC HOURLY
Copy & paste the text into a text editor and save it as a .bat file to make it executable.
When running this script you will setup a scheduled task which runs the robocopy.bat file every hour. Really great and time-saving if you work in a local folder on your C drive and wish to periodically take incremental backups to a network storage for instance.
Please note you must have access to a user account with NTFS permissions to access the file share (unless it’s open to everyone).
Open command prompt
Type the following command: net use x: \\server\share /user:domain\username password
Example: net use y: \\itdb1\home /user:itdb\kek 123456
If the share is open for everyone, you can dismiss the user arguments: net use y: \\itdb1\home
Keep in mind that if you already are on the domain and try to map a network share with another user than you’re currently logged in with, you will see the error message:
System error 1219 has occured.
Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.
Linux can also access NTFS mounts. Run the following commands in your terminal:
Create a folder which will be used for connecting to the share: $ sudo mkdir /mnt/ShareName
Mount the network share to your folder:
Without user authentication: $ sudo mount -t cifs //server/share /mnt/ShareName
With user authentication: $ sudo mount -t cifs -o username=itdb\kek,password=123456 //itdb1/home /mnt/ShareName
This will create a job entry in cron which starts every night at 0400 AM. What it does is running mysqldump to backup the specified <dbname> and also compresses it to a gzip file and saves it to /mnt/nas/ (replace with wherever you want to store the file).
Open Windows Explorer and navigate to: C:\Windows\System32
Hold the [Shift] button and right-click on compmgmt.msc and press Run as administratororRun as other userif you wish to use another user.
Method #2 – Command prompt
Open the Command Prompt and enter: runas /user:domain\username "mmc compmgmt.msc" Note: You must include mmc to inform the runas command that this is a Microsoft Management Console snap-in instead of an ordinary Win32 application
Method #3 – Context options menu
Simply right-click on Computer or This PC from the Startmenu or Windows Explorer and click on Manage. In most circumstances this will trigger the UAC prompt
In addition to compmgmt.msc, here are some other useful Windows snap-ins:
compmgmt.msc – Computer management
lusrmgr.msc – Local users and groups
perfmon.msc – Resource monitor
devmgmt.msc – Device manager
printmanagement.msc – Print management
taskschd.msc – Task scheduler
services.msc – Services
Find more snap-ins by going to %windir%\system32 and searching for *.msc files.