Introduction
SSH (Secure Shell) is a network protocol that enables secure remote connections between two systems. System admins use SSH utilities to manage machines, copy, or move files between systems. Because SSH transmits data over encrypted channels, security is at a high level.
This article will guide you through the most popular SSH commands. The list can also serve as a cheat sheet and will come in handy the next time you need to complete a task.
- An SSH client of your choice
- An SSH server on the remote machine
- The IP address or name of the remote server
You can generate an SSH key pair directly in cPanel, or you can generate the keys yourself and just upload the public one in cPanel to use with your hosting account. When generating SSH keys yourself under Linux, you can use the ssh-keygen command. Jun 13, 2019. All Mac and Linux systems include a command called ssh-keygen that will generate a new key pair. If you're using Windows, you can generate the keys on your server. Just remember to copy your keys to your laptop and delete your private key from the server after you've generated it. To generate an SSH key pair, run the command ssh-keygen. Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key. When adding your SSH key to the agent, use the default macOS ssh-add command, and not an application installed by macports.
Installation of SSH Keys on Linux - A Step-By-Step Guide. Outlined below is a step-by-step guide detailing the process of installing SSH Keys on a Linux server: Step One: Creation of the RSA Key Pair. The first step in the installation process is to create the key pair on the client machine, which would, more often than not, be your own system.
To connect to a remote machine, you need its IP address or name. Load the terminal or any SSH client and type
ssh
followed by the IP address:or name:
The first time you connect to a host, you’ll see this message:
Type yes and hit enter. You may need to enter your password as well.
SSH uses the current user when accessing a remote server. To specify a user for an SSH connection, run the command in this format:
Generate Ssh Key Linux Command Server
For instance:
By default, the SSH server listens for a connection on port 22. If the port setting in the SSH config file has been changed, you’ll need to specify the port. Otherwise, you will get this error:
To connect to a remote host with a custom SSH port number, use the
-p
flag. For example:To improve the security of SSH connections, generate a key pair with the keygen utility. The pair consists of a public and private key. The public key can be shared, while the private key needs to stay secure.
SSH key pairs are used to authenticate clients to servers automatically. When you create an SSH key pair, there is no longer a need to enter a password to access a server.
On the host machine’s terminal, use this command to create a key pair:
To use default settings, hit Enter on the prompts for file location and passphrase.
To use the key pair for SSH authentication, you’ll need to copy the public key to a server. The key is the file id_rsa.pub previously created with SSH keygen utility.
To copy your key to a server, run this command from the client:
You can also specify a username if you don’t want to use the current user.
Enter the password to authenticate when asked. After this, you will no longer need to use the password to connect to the same server.
You can securely copy files over the SSH protocol using the SCP tool. The basic syntax is:
For example, to copy a file sample3 to your Desktop on a remote server with a username test, type in:
The output shows a summary of the operation.
Make sure to use the uppercase
-P
flag if you need to specify the port.You can control how remote users can access a server via the SSH. Edit the settings in the
sshd_config
file to customize SSH server options. Make sure to edit only the options you are familiar with. A server can become inaccessible due to bad configuration.Use the editor of your choice to edit the file. You’ll need superuser permissions to make changes. In Linux, we use vim:
In the command line on a remote host, type in:
Enter the sudo password, and the shell opens the file in the editor you used.
When you make changes to the SSH configuration, you’ll need to restart the service in Linux.
Depending on the Linux distro, run one of the following commands on the machine where you modified the settings:
or:
Finally, enter the password to complete the process. As a result, the next SSH session will use the new settings.
Working on a remote server using SSH requires knowing basic SSH commands. Use the commands and options in this article to manage a remote host. Note that you can combine the flags to get the output you need.
Use the
pwd
command to show the file system path.The output displays the location of the directory you are in.
To list the contents of a current working folder, use the ls command.
The shell will show the names of all directories, files, and links. To get more information, add one of the following flags:
-a
displays hidden files and entries starting with a dot.-l
shows file details for directory contents. For example, the output includes permissions, ownership, date, etc.-s
lists the size of files, in blocks. Add -h to show the size in a humanly-readable form.
To navigate to a specific folder, use the
cd
command and a name or path of a directory.Remember that the names are case sensitive. Use
cd
without a name or path to return to the user’s home directory.Useful
cd
options include:cd .
go to the directory one level higher than your current location.cd -
switch to the previous directory.cd /
go to the root directory.
Use the
cp
command to copy a file or directory. You’ll need to include the name of the file and the target location.To copy file1 from Desktop to Dir1, type in:
To change the name of file1 while copying it to another destination, use this format:
This command copies file1 to Dir1 with a name you specify.
To copy a directory and its contents, use the -r flag in this format:
The
mv
command works in the same manner as the copy command.For instance, to move a file to another location, type in:
The
touch
command allows you to create a new file with any extension.In the terminal, enter the following command:
For example, to create a system.log file, type in:
To create a directory, use the
mkdir
command. Enter a new directory name or full path in this format:Or:
Star Wars Battlefront CD Key Serial Key Generator Keygen Crack. 158 likes 2 talking about this. Star Wars Battlefront CD Key Serial Key Generator Keygen Crack For Pc, Xbox 360, Ps3, Xbox One and Ps4. Expand your galaxy with the Star Wars Battlefront Season Pass. Get 4 upcoming expansion packs filled with new content that will take you to new locations across a galaxy far, far away. Act now to secure two-week early access to each expansion pack and an exclusive “Shoot First” emote. Star wars battlefront season pass key generator. Why spend your money when you can get Star Wars Battlefront Free CD Key on this website simple and free! On this website you can use our Star Wars Battlefront Free CD Key present code generator to create Free Star Wars Battlefront Free CD Key and Product Codes!
To delete a Linux file , use
rm
in this format:In addition, you can enter a full path:
To delete a directory, add the
-r
flag to the rm command.To view the status of all network adapters, use the
ifconfig
command. Moreover, when you don’t use any options with ifconfig, the output displays only active interfaces.To clear the current working area of your bash screen, type
clear
in the shell. This command clears one portion of the screen and shifts up the previous output.To remove the output from the terminal completely, use the
reset
command.Run a Command on a Remote Server from a Local Computer
This method does not create a new shell. Instead, it runs a command and returns the user to the local prompt. You can create a file, copy files, or run any other SSH command in this format.
To remotely execute a command from the local machine, append an instruction to the SSH command. For example, to delete a file, type in:
Enter the password, and the file on the remote server will be deleted without creating a new shell.
The SSH tool comes with many optional parameters. The table below lists common SSH options and the corresponding descriptions.
SSH Option | Description |
-1 | Instructs ssh to use protocol version 1 |
-2 | Instructs ssh to use protocol version 2. |
-4 | Permits only IPv4 addresses. |
-6 | Permits only IPv6 addresses. |
-A | Enables authentication agent connection forwarding. Use this option with caution. |
-a | Disables authentication agent connection forwarding. |
-b bind_address | Use this option on the local host with more than one address to set the source address of the connection. |
-C | Enables data compression for all files. Only to be used with slow connections. |
-c cipher_spec | Use to select a cipher specification. List the values separated by a comma. |
-E log_fileName | Attaches debug logs to log_file instead of standard error. |
-f | Sends ssh to background, even before entering a password or passphrase. |
-g | Permits remote hosts to connect to ports forwarded on a local machine. |
-q | Runs ssh in quiet mode. It suppresses most error or warning messages. |
-V | Displays the version of ssh tool and exits. |
-v | Prints debugging messages for ssh connection. The verbose mode is useful when troubleshooting configuration issues. |
-X | Use this option to enable X11 forwarding. |
-x | Disable X11 forwarding. |
This article has covered the 19 most popular commands for using the SSH tool effectively. Now you can manage your server remotely with an added layer of security and have these commands at your fingertips.
Before executing these commands and options on a live server, we do recommend using a test machine first.
Next you should also read
The article covers the 5 most common and efficient ways to secure an SSH connection. The listed solutions go…
This article provides all the information you need in order to set up SSH encryption on your remote device.…
If you are using Debian 9 or Debian 10 to manage servers, you must ensure that the transfer of data is as…
When establishing a remote connection between a client and a server, a primary concern is ensuring a secure…
MySQL is an open-source relational database server tool for Linux operating systems. It is widely used in…
Introduction
Secure Shell (SSH) is an encrypted protocol used by Linux users to connect to their remote servers.
Generally, there are two ways for clients to access their servers – using password based authentication or public key based authentication.
Using SSH keys for authentication is highly recommended, as a safer alternative to passwords.
This tutorial will guide you through the steps on how to generate and set up SSH keys on CentOS 7. We also cover connecting to a remote server using the keys and disabling password authentication.
1. Check for Existing Keys
Prior to any installation, it is wise to check whether there are any existing keys on the client machines.
Open the terminal and list all public keys stored with the following command:
The output informs you about any generated keys currently on the system. If there aren’t any, the message tells you it cannot access
/.ssh/id_*.pub
, as there is no such file or directory.2. Verify SSH is Installed
To check if thw package is installed, run the command:
If you already have SSH, the output tells you which version it is running. Currently, the latest version is OpenSSH 8.0/8.0p1.
Note: Refer to our guide If you need to install and enable SSH on your CentOS system.
Steps to Creating SSH keys on CentOS
Step 1: Create SSH Key Pair
1. Start by logging into the source machine (local server) and creating a 2048-bit RSA key pair using the command:
If you want to tighten up security measures, you can create a 4096-bit key by adding the -b 4096 flag:
2. After entering the command, you should see the following prompt:
3. To save the file in the suggested directory, press Enter. Alternatively, you can specify another location.
Note: If you already have a key pair in the proposed location, it is advisable to pick another directory. Otherwise it will overwrite existing SSH keys.
4. Next, the prompt will continue with:
Although creating a passphrase isn’t mandatory, it is highly advisable.
5. Finally, the output will end by specifying the following information:
Now you need to add the public key to the remote CentOS server.
You can copy the public SSH key on the remote server using several different methods:
- using the ssh-copy-id script
- using Secure Copy (scp)
- manually copying the key
The fastest and easiest method is by utilizing
ssh-copy-id
. If the option is available, we recommend using it. Otherwise, try any of the other two noted.1. Start by typing the following command, specifying the SSH user account, and the IP address of the remote host:
If it is the first time your local computer is accessing this specific remote server you will receive the following output:
2. Confirm the connection – type yes and hit Enter.
3. Once it locates the
id_rsa.pub key
created on the local machine, it will ask you to provide the password for the remote account. Type in the password and hit Enter.4. Once the connection has been established, it adds the public key on the remote server. This is done by copying the
~/.ssh/id_rsa.pub
file to the remote server’s ~/.ssh
directory. You can locate it under the name authorized_keys
.5. Lastly, the output tells you the number of keys added, along with clear instructions on what to do next:
1. First, set up an SSH connection with the remote user:
2. Next, create the
~/.ssh
directory as well as the authorized_keys
file:3. Use the chmod command to change the file permission:
chmod 700
makes the file executable, while chmod 600
allows the user to read and write the file.4. Now, open a new terminal session, on the local computer.
5. Copy the content from
id_rsa.pub
(the SSH public key) to the previously created authorized_keys
file on the remote CentOS server by typing the command:With this, the public key has been safely stored on the remote account.
1. To manually add the public SSH key to the remote machine, you first need to open the content from the
~/.ssh/id_rsa.pub
file:2. As in the image below, the key starts with ssh-rsa and ends with the username of the local computer and hostname of the remote machine:
3. Copy the content of the file, as you will need later.
4. Then, in the terminal window, connect to the remote server on which you wish to copy the public key. Use the following command to establish the connection:
5. Create a ~/.ssh directory and authorized_keys file on the CentOS server with the following command:
6. Change their file permission by typing:
7. Next, open the
authorized_keys
file with an editor of your preference. For example, to open it with Nano, type:8. Add the public key, previously copied in step 2 of this section, in a new line in (under the existing content).
9. Save the changes and close the file.
10. Download putty key generator for windows 8. Finally, log into the server to verify that everything is set up correctly.
Once you have completed the previous steps (creating an RSA Key Pair and copying the Public Key to the CentOS server), you will be able to connect to the remote host without typing the password for the remote account.
All you need to do is type in the following command:
If you didn’t specify a passphrase while creating the SSH key pair, you will automatically log in the remote server.
Otherwise, type in the passphrase you supplied in the initial steps and press Enter.
Once the shell confirms the key match, it will open a new session for direct communication with the server.
Although you managed to access the CentOS server without having to provide a password, it still has a password-based authentication system running on the machine. This makes it a potential target for brute force attacks.
You should disable password authentication entirely by following the outlined steps.
Note: Consider performing the following steps through a non-root account with sudo privileges, as an additional safety layer.
1. Using the SSH keys, log into the remote CentOS server which has administrative privileges:
2. Next, open the SSH daemon configuration file using a text editor of your choice:
3. Look for the following line in the file:
4. Edit the configuration by changing the
yes
value to no
. Thus, the directive should be as following:5. Save the file and exit the text editor.
6. To enable the changes, restart the sshdservice using the command:
6. To enable the changes, restart the sshdservice using the command:
7. Verify the SSH connection to the server is still functioning correctly. Open a new terminal window and type in the command:
In this article, you learned how to generate SSH key pairs and set up an SSH key-based authentication. We also covered copying keys to your remote CentOS server, and disabling SSH password authentication.
Next, You Should Read: