MALIKA KAROUM

MALIKA KAROUM

  • Home
  • Inleiding
  • Unite Arab Emirates
  • Blog
  • video’s
  • Promotion
    • Worth for free now
    • Work from Home 2023
    • Gadgets
    • All about Windows
    • about Whatsapp
    • Whats the
    • About websites
    • New Ways
    • New Way of Watching
    • Virtual
    • Website
    • All about Video
    • How to Use
    • YouTube Info
    • All about Twitter
    • The Best of
    • About Apps
    • Google News
    • For Free
    • About This
    • Need More
    • Why should you
    • Iphone news
    • Interesting News
    • About Amazone
    • Some tips
    • About Netflix
    • All about Music
    • About Facebook
  • Marketing
    • Malika Karoum Strategie Modules
    • Malika Karoum Online Marketing
    • Malika Karoum Business Service
    • Malika Karoum Marketing Platform
    • Online business marketing
  • Luxury
    • The Indulgence Business site
    • The Luxury Web site
    • The Ultimate Indulgence
    • The Indulgence Site
    • The Ultimate Luxury Information site
    • Online luxury
  • Malika Karoum
    • Malika Karoum LinkedIn
    • Malika Karoum Facebook
    • Malika Karoum Instagram
    • Malika Karoum Business News
    • Adverteren grote fraude
    • Menu POS
    • Malika Karoum Evenementen
  • Security
  • Malika Karoum link
  • Home
  • Malika Karoum Global News
  • Efficiently Manage Remote SSH Connections With These Linux Commands
June 8, 2023

Efficiently Manage Remote SSH Connections With These Linux Commands

Efficiently Manage Remote SSH Connections With These Linux Commands

by Malika Karoum / Tuesday, 12 January 2021 / Published in Malika Karoum Global News

 

If you run one or more remote servers, you’re typically spending time constantly logging in throughout the day.

But it doesn’t have to be this way. It’s time you learned how to efficiently login via SSH with only an alias, transfer single files or directories, execute remote SSH commands, and effortlessly mount remote servers to local directories.

SSH Config File

One huge time saver is the SSH config file located at ~/.ssh/config. Start by creating a directory to store all the SSH keys you use to login to servers with the command:

mkdir -m 0600 $  HOME/.ssh_keys

Now copy all of your SSH key files into this directory (eg. clienta.pem, clientb.pem, etc.). Next, open up the ~/.ssh/config file in a text editor by running the command:

nano ~/.ssh/config

Below is an example entry that will establish an SSH connection with a remote server:

host clienta
    hostname 124.58.2276.80
    user ubuntu
    IdentityFile ~/.ssh_keys/clienta.pem

Add sections of lines such as above to the ~/.ssh/config file, one for each server you desire. Then save and close the file by pressing Ctrl+X and follow the prompt. Once saved, you can now login to any server via SSH from any directory within terminal with the simple command:

ssh clienta

This will instantly log you into the server with the information under the clienta host you specified within the ~/.ssh/config file.

Transfer Files With Scp / Rcp

Without creating a persistent login session, you can easily upload single files or directories to a remote server with the scp command, such as:

scp report.pdf clienta:~/

The above command will upload the report.pdf file from your local computer to the home directory of the clienta server you defined in the above section. You may upload to a directory other than the home directory such as:

scp about.html clienta:/home/clienta/public_html

The above will upload the about.html file to the /home/client/public_html directory on the remote clienta server. It is also possible to upload entire directories using the -r option such as:

scp -r Documents clienta:~/docs

This will upload the entire ~/Documents directory from your local computer to the ~/docs directory of the remote server.

Downloading Files

Similarly, you can download files or directories to your local computer without creating a persistent login session using the rcp command such as:

rcp clienta:~/public_html/about.html myproject/about.html

The above will download the public_html/about.html file from the remote clienta server, and place it into the projects/about.html file on your local computer.

Execute Remote SSH Commands

Another quick tip is you can execute single Linux commands on a remote server without a persistent login session, such as:

ssh clienta ls

The above will execute the ls command on the remote clienta> server, and list all files / directories without keeping you logged into the server. For example, if you wanted to restart a server you could use:

ssh clienta /sbin/shutdown -rf now

Local /bin Directory

Let’s expand on this by allowing easy mounting to remote servers by creating a /bin/ directory that’s local to our user account. Open terminal on your computer, and create a /bin/ directory by running the command:

mkdir -m 0755 ~/bin

Next, open the ~/.profile file in a text editor with the command:

nano $  HOME/.profile

Scroll down to the very bottom of the file, and add the following lines by copying them to your clipboard, then within terminal by pressing Ctrl+Shift+V:

if [ -d "$  HOME/bin" ] ; then
    PATH="$  HOME/bin:$  PATH"
fi

Save and close the file by pressing Ctrl+X, and follow the prompt. This will save the .profile file, which will check the newly created local /bin/ directory for any commands you try to run.

Adding Remote Mount Commands

First, check and see whether or not sshfs is installed on your computer with the command:

sshfs --version

If this prints out the current version of sshfs, then you’re all set. Otherwise if you receive a “command not found” error, you may install sshfs with the following command:

sudo apt-get -y install sshfs

Now create a /mnt/ directory that will contain all the mounted directories to our remote servers. Within terminal run the commands such as:

mkdir -m 0755 ~/mnt
mkdir -m 0755 ~/mnt/clienta
mkdir -m 0755 ~/mnt/clientb

Continue creating one sub-directory for each remote server you may potentially mount to. Next, let’s create the shell commands that we will run, and for example, for the clienta server open a file by running the following command in terminal:

nano ~/bin/mount_clienta

Modify the below line as necessary with the proper server information, then copy and paste it into the blank text editor within terminal by pressing Ctrl+Shift+V:

#!/bin/bash
sshfs -o IdentityFile=~/.ssh_keys/clienta.pem ubuntu@192.168.0.24:/var/www ~/mnt/clienta

Save and close the file by pressing Ctrl+X, and follow the prompts to close the file. Finally, change permissions of the file so it’s executable by running the command:

chmod 0755 ~/bin/mount_clienta

Now any time you need to mount to clienta’s remote server to transfer files to / from it, from any directory within terminal you can simply run the command:

mount_clienta

The directory on your local computer at ~/mnt/clienta will now be mounted to the /var/www directory of the remote server. You can begin copying files to and from the directory just as you would any local directory, and the necessary operations will occur on the remote server.

More Efficient connection Management

Hopefully the above tips have helped streamline and made more efficient the management of your connections to remote servers. In this article you have learned all about the ~/.ssh/config file allowing you to login via SSH with only an alias, transfer single files / directories, execute remote SSH commands, and how to easily mount a local directory to remote servers.

MakeUseOf – Feed

  • Tweet
Tagged under: Commands, Connections, Efficiently, Linux, Manage, Remote, These

About Malika Karoum

What you can read next

Wi-Fi Direct: Windows Wireless File Transfer That’s Faster Than Bluetooth
The Top 20 Most Popular Artists on Spotify
How to Change Alexa’s Voice: Language, Accent, and Speed

Malika Karoum Blog 2023

  • How to Delete the Last 15 Minutes of Your Google Search History

    There’s a quick way for you to clear your...
  • Lenovo Wants You to Know Its Yoga Pad Pro Can Be Used as a Portable Switch Display

    Sometimes, when playing with your Nintendo Swit...
  • The 5 Best Apps for Buying and Selling Pre-Owned Books

    We’ve all been at the point where we have...
  • Humble’s Recent "Heal Covid-19" Bundle Raised 1.2 Million for Charity

    To help raise money for COVID-19 relief in Indi...
  • Nintendo Partners With PlayVS to Make Its Games Recognized High School Varsity Athletics

    It’s odd—Nintendo gets a lot of flak for ...
  • The Pros and Cons of Playing Video Games on an Emulator

    If you’re a fan of playing retro video ga...
  • 5 Curators to Find the Best Articles Worth Reading on the Internet

    When anyone and everyone is a publisher, it isn...
  • Apple Could Unveil iPads With OLED Screens in 2023

    Apple only just switched from LCD to mini-LED d...
  • What Is Signal and How Does It Work?

    The chances are that you use at least one of th...
  • Samsung’s Upcoming Flagship Exynos Chipset Will Feature AMD’s RDNA2 GPU

    AMD confirmed its partnership with Samsung at C...
  • Atari Finally Reveals the Launch Date for the New Atari VCS Console

    At last, after what seems like an age (it pract...
  • Twitter Starts Testing Full-Screen Ads in Fleets

    Twitter has announced that it will be adding fu...
  • When Is Facebook Messenger Going to Offer End-to-End Encryption?

    Facebook Messenger is easy to use and has great...
  • Get Paid to Play Apps: How They Work and What You Risk

    You’ve probably seen advertisements for a...
  • When Will PS5 Production Ensure Supply Meets Demand?

    Despite the PS5’s launch taking place in ...
  • How to Manage Processes on Ubuntu Using System Monitor

    Linux, like most modern operating systems, is v...
  • How to Get Verified on Twitter and Finally Get That Blue Check Mark

    Twitter, like most social media platforms, offe...
  • 10 Street Photography Tips That Will Make You a Better Photographer

    Street photography is enjoyed by many enthusias...
  • Huawei Freebuds 4i Review: Quality ANC Earbuds for $100

    Huawei Freebuds 4i 8.00 / 10 Read Reviews Read ...
  • What Is Extended Reality (XR) and How Does It Work?

    We’re living in a digital age where the virtual...

MALIKA KAROUM ONLINE MARKETING PLATFORM

Office:
RME HOLDINGS SARL – DUBAI BRANCH

BUSINESS CENTER

Parcel ID: 345-835

Area: Bur Dubai

Sub Area: Burj Khalifa

UNITED ARAB EMIRATES

 

 

 

Malika Karoum Concept

Malika Karoum Projects

  • GET SOCIAL

© 2014 Malika Karoum -United Arab Emirate Dubai- All Rights Reserved

TOP