Posts Under Category: SSH

If for some reason you do not want to update your server kernel but want to update other packages running on CentOS, here is how you can do.

Update can be done using yum command and to exclude kernel from update we need to add exclude command.
Login to your server as root via SSH and run following command:

yum -y --exclude=kernel\* update

OR

yum -y -x 'kernel*' update

Above command will update all packages but will leave kernel update on a CentOS server.

Our Recommended VPS Hosting

If you want to copy a file / folder from one server to another, you can use wget or scp command. In this tutorial I will show how to use scp command to copy files / folder from one server to another.

Let us suppose

Server One IP is: 1.1.1.1
Server Two IP is: 2.2.2.2

How to copy a file

Suppose you want to copy a file from server one to server two.
Location of file on server one is: /home/filename.txt

Login to server two via SSH and run following command

scp root@1.1.1.1:/home/filename.txt /home/

This will copy filename.txt file from server one to server two and save in /home directory.

How to copy a folder / directory

Suppose you want to copy a complete folder from server one to server two.
Let’s say you want to copy /backup folder from server one to server two.

Login to server two via SSH and run following command

scp -r root@1.1.1.1:/backup /foldername

This will copy /backup directory from server one to server two and save in /foldername directory.

Our Recommended VPS Hosting

PuTTY is a free and open-source SSH / telnet client for Windows and Unix platforms.
A newbie can find it difficult how to use copy / paste in putty.

How to copy in putty

Using left click of your mouse select the text you want to copy.
That’s it. The selected text will be copied to your clipboard.

How to paste in putty

Simply right click and it will paste the copied text.

Our Recommended VPS Hosting

If you use ping command in SSH, it will continue pinging and extending output lines without any stoppage. Something like below screenshot.
stop-ping

Here is how you can exit from ping command. Simply press below key on your keyboard.

Ctrl + C

Our Recommended VPS Hosting

The default SSH port on centOS 7 (32-bits / 64-bits) server is 22. But for security reasons, it is recommended to change the default SSH port number. Here is how you can change your centOS 7 server / VPS SSH port number.

Step 1:

Login to your server as root via SSH.

Step 2:

Backup the configuration file before editing it.

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

Step 3:

Open following file in any text editor like nano.

nano /etc/ssh/sshd_config

Step 4:

Find following code in /etc/ssh/sshd_config file.

#Port 22

Change this line to new port number and remove #
Like if we want to make 2121 as new ssh port number.

Port 2121

Save the change using: Ctrl + O
Exit nano editor using: Ctrl + X

Step 5:

Allow the new port in firewall. If you use any third party firewall like csf firewall, add the new port in allowed port list.
If you are using default OS firewall, use following command to allow new port.
Below command will allow port 2121.

firewall-cmd --add-port 2121/tcp --permanent
firewall-cmd --add-port 2121/tcp

Step 6:

Restart SSH using below command.

service sshd restart

Don’t close your current SSH session. Instead start a new SSH session in a new widows with new SSH port number.
If you are able to login using new SSH port number, you have successfully changed your server SSH port number.

If you are unable to login using new SSH number, it means you have done something wrong. You should consider reverting all changes made in step 3.

Our Recommended VPS Hosting

We generally use wget command to download any particular file on a server. But what if I want to download a complete directory / folder.

Here is how you can download a full directory / folder using wget SSH command. Suppose, I want to download all files and folders under http://www.lophost.com/foldername

So, my SSH command will be:

wget -r http://www.lophost.com/foldername/

Our Recommended Dedicated Server

cPanel offers you to schedule backup and retain backup of server and accounts. But if you need to run backup manually, you can do it from SSH. Login to your server as root via SSH and run following command.

For cPanel new Backup system

/usr/local/cpanel/bin/backup

If the backup is up-to-date, you can force to run backup using below command

/usr/local/cpanel/bin/backup --force

For cPanel Legacy backup system

/scripts/cpbackup

If the backup is up-to-date and you wish to run backups anyway, use:

/usr/local/cpanel/scripts/cpbackup --force

Our Recommended Dedicated Server

Please follow below steps to change root password via SSH of a dedicated server / VPS.

Step 1:

Login as root to your server via SSH.
login-root

Step 2:

Run below command

passwd

Step 3:

Enter your new password and press enter.
enter-new-password

Step 4:

Re-enter your new password to confirm the password.
re-type-password

If completed successfully, the shell will show you a successful message showing

passwd: all authentication tokens updated successfully.

root password changed

Done!!!

Our Recommended VPS Hosting

How to create a file via SSH

To create a file via SSH use touch command.
Like I want to create a file lophost.text in /home, I will use below command

touch /home/lophost.txt

This will be a blank file, which we can edit later.

How to create a folder / directory via SSH

Use command mkdir to create a new folder / directory. Like I want to create a folder lophost in /home

mkdir /home/lophost

Our Recommended Dedicated Server

CD command is used for navigation to different directories on a Linux machine. Below I have explained some basic things about CD command.

How to know current directory

If you want to know your current directory, run below command:

pwd

ssh-pwd command

Default directory for root

when you login as root your default directory is

/root

How to move to another directory

Support you want to move to /home directory, use below command

cd /home

To go up a directory

To move to one level up directory use:

cd ..

To go to Top level

cd /

To go to your home directory

cd ~

This will take the use to his home directory. Like for user root home directory is /root

Our Recommended Dedicated Server