How to use SSH

Table of contents:

How to use SSH
How to use SSH
Anonim

If you want to connect to another computer, and everything around is so insecure and unreliable, and your data is so valuable and important … only SSH can help you. Of course, you first need to configure SSH, then create an encrypted connection to the server, and for this you need to have SSH enabled on both sides of the connection. In any case, if you want your connection to be as secure as possible, read this article and play with it!

Steps

Method 1 of 3: Part: First Connection

Use SSH Step 1
Use SSH Step 1

Step 1. Install SSH

For Windows, you need to download and install an SSH client. Most often, they take Cydwin, a free SSH client. However, it is not necessary to limit yourself to it, you can also download PuTTY.

  • When installing Cydwin, you need to choose the option to install OpenSSH from the Internet.
  • It's easier with Linux and Mac OS - SSH is already built into the system. Why? This is the magic of UNIX systems.
Use SSH Step 2
Use SSH Step 2

Step 2. Start SSH

Open your installed Cydwin terminal or a regular terminal (on Linux and Mac OS). SSH is just a terminal, only a console. The graphical interface was not delivered, so get used to typing commands.

Use SSH Step 3
Use SSH Step 3

Step 3. Check the connection

Before diving into the world of a secure Internet, you need to check if everything is working correctly - both your computer and the system you are connecting to. To do this, you will have to type the following command (and do not forget to replace username with your username on the remote computer, and remote with, in fact, the address of the remote computer or server):

  • $ ssh @

  • When the connection is established, you will be asked for a password. Enter the password and do not be alarmed: yes, the cursor does not move, and the characters do not appear - this is how it should be.
  • If nothing came of it, then either your SSH is configured crookedly, or it is not up on the remote computer.

Method 2 of 3: Part: Basic Commands

Use SSH Step 4
Use SSH Step 4

Step 1. Go to the SSH shell

When you first connect to a remote computer, you should be in the HOME folder. In order to navigate through folders, the cd command comes in handy:

  • cd..

    - go one directory up
  • cd

    - go to a specific subdirectory
  • cd / home / directory / path /

    - transition to a specific directory from root (home)
  • cd ~

    - go back to the Home folder
Use SSH Step 5
Use SSH Step 5

Step 2. Check the contents of the folders

To see files and folders, you need the ls command:

  • ls

    - will display a list of files and folders in the given directory
  • ls –l

    - will display a list of folder contents and additional information (size, rights, date)
  • ls-a

    - will display a list of all content, including even hidden
Use SSH Step 6
Use SSH Step 6

Step 3. Copy files from your computer to the remote computer

Yes, it also happens that you need to upload something from yourself to a remote computer. How? scp to help you!

  • scp /localdirectory/example1.txt @:

    - will copy example1.txt to the remote computer folder specified in. If left blank, the file will be copied to root.
  • scp @: / home / example1.txt./

    - will move example1.txt from the root folder of the remote computer to the current folder of the local computer.
Use SSH Step 7
Use SSH Step 7

Step 4. Copy the files through the shell

With the cp command, you can make copies of files in the same directory, or in a directory of your choice:

  • cp example1.txt example2.txt

    - will create in the same folder a copy of example1.txt called example2.txt
  • cp example1.txt /

    - will create a copy of example1.txt in the folder specified in.
Use SSH Step 8
Use SSH Step 8

Step 5. Move and rename files

If you want to change the file name or move it without copying, then use the mv command:

  • mv example1.txt example2.txt

    - will rename example1.txt to example2.txt. The file will remain in the same folder where it was.
  • mv directory1 directory2

    - will rename the directory1 folder to directory2. The contents of the folder will not change.
  • mv example1.txt directory1 /

    - will move example1.txt to directory1.
  • mv example1.txt directory1 / example2.txt

    - will move example1.txt to directory1 and rename it to example2.txt.
Use SSH Step 9
Use SSH Step 9

Step 6. Delete files and folders

If you want to do something like this, then arm yourself with the rm command:

  • rm example1.txt

    - will remove example1.txt.
  • rm –I example1.txt

    - will remove example1.txt, asking for confirmation.
  • rm directory1 /

    - will delete the directory1 folder along with all its contents.
Use SSH Step 10
Use SSH Step 10

Step 7. Change the access rights to your files

Read and write permissions are changed with the chmod command:

  • chmod u + w example1.txt

    - will add the right to write / modify the file to the user (u). You can use the modifiers (g) or (o), if the corresponding rights need to be given to a group or generally to all users.
  • chmod g + r example1.txt

    - will add the right to read the file to the group.
  • In general, there are many permissions to access files, so study this aspect yourself.
Use SSH Step 11
Use SSH Step 11

Step 8. Learn to read the commands

There are a few more important commands to be aware of. For example:

  • mkdir newdirectory

    - will create a new subdirectory called "New Folder" or something like that.
  • pwd

    - will show which folder you are in now.
  • who

    - will show who is authorized in the system.
  • pico newfile.txt

    or

    vi newfile.txt

    - will create a new file and open a text editor. Different systems have different editors, keep this in mind. The most commonly encountered are pico and vi. Accordingly, different editors have different commands.
Use SSH Step 12
Use SSH Step 12

Step 9. Get detailed information about any team

If you do not know what will happen if you enter this or that command, then call the help and educate yourself!

  • man

    - will display information about the team.
  • man –k

    - will search all pages created by users for the keyword you entered.

Method 3 of 3: Part: Generating Encrypted Keys

Use SSH Step 13
Use SSH Step 13

Step 1. Create your SSH keys

These keys will allow you to connect to a remote computer without having to constantly enter a password. And this, by the way, is very secure, because the password will no longer be constantly transmitted back and forth over the network.

  • Create a folder for the key using the command:

    $ mkdir.ssh

  • Create public and private keys using the command:

    $ ssh-keygen –t rsa

  • Creating a passphrase for keys is optional. If you do not want, then just press "enter" when the system prompts you to create a pass phrase. This will create two keys in the id_rsa and id_rsa.pub directories
  • Change the access rights to your private key. So that only you can read it, enter the command:

    $ chmod 600.ssh / id_rsa

Use SSH Step 14
Use SSH Step 14

Step 2. Place the public key on the remote computer

The keys have been created, but that's only half the battle. Now we need to upload the public key to the remote computer to put an end to the leapfrog with passwords. Replacing the relevant snippets, enter the following command:

  • $ scp.ssh / id_rsa.pub @:

  • Don't forget the colon at the end.
  • Enter the password before starting the file transfer.
Use SSH Step 15
Use SSH Step 15

Step 3. Install the public key on the remote computer

Have you posted the key? Okay, 75% of the case is done. Now you need to install it, without it nothing will work. So, log in to the remote computer in the same way as you did in the third step.

  • Create an SSH folder on the remote computer if it doesn't already exist:

    $ mkdir.ssh

  • Add your key to the authorized keys file. If such a file does not exist, it must be created:

    $ cat id_rsa.pub >>.ssh / authorized_keys

  • Change the permissions for the SSH folder:

    $ chmod 700.ssh

Use SSH Step 16
Use SSH Step 16

Step 4. Check if the connection is working

Once the key is installed on the remote computer, you should be able to connect to the volume and not enter a password in the process. You can check the connection with the following command:

$ ssh @

Popular by topic