Knowledge Base

Your Go-To Resource for Expert Insights and Solutions

Dedicated Server

Copying Files from Server to a Localhost Using SCP or Rsync Using Command Line

When you're working with files on your local machine and need to transfer them to a server, you can use secure and efficient tools like scp (secure copy) or rsync. These commands are simple to use and can make file transfer processes seamless, whether you're working on an Ubuntu or CentOS server.

Step 1: Install Necessary Tools

Both scp and rsync come pre-installed on most Linux distributions. However, if they're not installed, you can easily install them.

For Ubuntu or other Debian-based systems, use the following command:

Code copied to your clipboard!

If you're using CentOS or Red Hat-based systems, use this command:

Code copied to your clipboard!

Step 2: Copying Files with SCP

The scp command is a simple way to securely copy files over SSH. To use scp to transfer a file from your server to the local machine, use this command:

Code copied to your clipboard!

For example, if you want to copy a file named myfile.txt from your server to the /path/to/local/directory on your local machine, use:

Code copied to your clipboard!

Step 3: Copying Files with Rsync

The rsync command is another efficient tool for transferring files, and it has additional features like synchronization and incremental backups. Here's how you can use rsync to copy files to your local machine:

Code copied to your clipboard!

For example, to copy myfile.txt from your server to the /path/to/local/directory on your local machine, use:

Code copied to your clipboard!

Step 4: Verifying the Transfer

Once the file transfer is complete, you can verify it by checking the local directory.

Code copied to your clipboard!

Use the above command to list the contents of the target directory on your local machine and confirm that the file is present.

Conclusion

Whether you choose to use scp or rsync, both tools provide a secure and efficient way to copy files from your remote server to your local machine. The choice between the two depends on your specific needs, with rsync offering additional features like incremental file synchronization.

Now you're ready to securely transfer your files from your server to your local machine using the best tools available!

How to Create a New User and Add Them to Sudoers

In this tutorial, we will guide you through the process of creating a new user and giving them sudo privileges on a Linux system.

 

Step 1: Create a New User

To create a new user, use the useradd command:

Code copied to your clipboard!

Step 2: Set a Password for the New User

Next, set a password for the newly created user:

Code copied to your clipboard!

Step 3: Add the User to the Sudoers Group

To grant the new user sudo privileges, add them to the sudo group:

Code copied to your clipboard!

Step 4: Verify the User's Sudo Access

To check if the user has been added to the sudoers group successfully, use the following command:

Code copied to your clipboard!

Conclusion

You've successfully created a new user and granted them sudo privileges. The new user can now execute commands as a superuser by prefixing commands with sudo.

How to Change Your SSH Port Number to Avoid Attacks and Improve Security

SSH is one of the most common ways to access and manage servers. Unfortunately, its popularity also makes it a frequent target for hackers. By default, SSH runs on port 22, which is widely known and often scanned by attackers. But what if we told you that changing your SSH port number could dramatically improve the security of your server?

In this article, we’ll show you how to change your SSH port number and hide it from potential attackers, making your server more secure and less vulnerable to brute force and automated attacks.

 

Why Change Your SSH Port Number?

The default SSH port number (22) is a well-known target for attackers. It's the first port that malicious actors will try when attempting to gain unauthorized access to your server. By changing the port number to something more obscure, you make it more difficult for attackers to find and exploit your SSH service.

Changing the SSH port adds an extra layer of security by preventing automated scripts and brute-force attempts that typically target port 22. It’s a simple change, but it can greatly enhance the overall security of your server.

Step-by-Step Guide: Changing Your SSH Port

Follow these steps to change your SSH port number and increase your server's security:

  1. Log in to your server as root or a user with sudo privileges
  2. Open the SSH configuration file for editing:
    Code copied to your clipboard!
  3. Find the line that specifies the default SSH port. It will look like this:
    Code copied to your clipboard!
    Remove the "#" symbol to uncomment the line, and then change the port number to your desired value (for example, 2222, 2200, etc.):
    Code copied to your clipboard!
  4. Save the changes and close the file: Press CTRL + X, then Y to confirm changes, and hit Enter to save the file.
  5. Adjust your firewall rules to allow the new port: If you're using UFW, run the following command to allow traffic on your new port (replace 2222 with your port number):
    Code copied to your clipboard!
    Don't forget to remove the old rule for port 22:
    Code copied to your clipboard!
  6. Restart the SSH service to apply the changes:
    Code copied to your clipboard!
  7. Test the new SSH port by opening a new terminal window and trying to connect to the server with the new port:
    Code copied to your clipboard!
    Make sure you can log in successfully before closing your current SSH session.

Remember: Never Lock Yourself Out!

Before closing your SSH session, always make sure you can log in using the new port. Test the new connection in a separate terminal window to confirm that the change was successful and that you're not locking yourself out of the server.

Can I Change My Port Back Later?

Yes, you can always change your SSH port number back to 22 if necessary. Just follow the same steps, but revert the port number to 22. Remember to adjust your firewall rules and restart SSH after making the changes.

STAY TUNED
Image