SSH, or Secure Shell, performs like a remote administration protocol helping users control and modify their remote servers over the Internet.
For MAC and Linux users, SSH quite easy to attain and use In windows, you will need SSH clients to open SSH connections.
The most popular SSH client is none other than PUTTY.
For Linux and MAC, head over to the terminal and execute the following code
ssh {user}@{host}
Here, the user is the account you want to access and the host is the computer you want to access. It can be either a domain name or an IP address.
Tap enter to proceed. Via entering, as the next step, you are asked for the password of the requested account. Enter the password and hit enter. You will be connected to the remote terminal window.
BASIC SSH COMMANDS:
Here we will go through popular ssh commands with syntaxes and useful options.
SSH Command | Explanation |
ls | Show directory contents (list the names of files) |
cd | Change directory |
mkdir | Create a new folder (directory) |
|
rm | Remove a file |
|
pwd | Show current directory (full path to where you are right now) |
|
cp | Copy file/folder |
|
mv | Move file/folder |
|
grep | Search for a specific phrase in file/lines |
|
find | Search files and directories |
|
vi/nano | Text editors |
history | Show last 50 used commands |
clear | Clear the terminal screen |
tar | Create & Unpack compressed archives |
wget | File downloading from the internet |
du | Get file size |
Ls command:
ls command is used to list all files and directories.
cybrosys@cybrosys:/home$ ls
Cybrosys
Where cybrosys is the directory in the home directory.
Cd command:
cd is the short form of change directory, it is used to jump into the directory.
Syntax:
cd[directory]
cybrosys@cybrosys:/$ cd /home
cybrosys@cybrosys:/home$
You can also write the full path of the directory.
cybrosys@cybrosys:~$ cd /home/cybrosys/odoo
cybrosys@cybrosys:~/odoo$
cd / takes you to the root directory.
cybrosys@cybrosys:/home$ cd /
cybrosys@cybrosys:/$
mkdir command:
mkdir command is used to make directory.
Syntax:
mkdir [directory]
Example: mkdir yourFolder
touch command:
It is used to create a file.
Syntax:
One can create a file with or without extension. The extension can be anything.
rm command:
It is used to remove a file or directory.
Syntax:
rm [file name]
Example: rm main.py
To delete a folder, use -r to remove all files and subfolders in it.
Example:
rm -r home/cybrosys/folder
cat command:
It is used to display the content of a file.
Syntax:
cat [file name]
cp command:
It is used to copy files and folders
Syntax:
cp [options] [source] [destination]
mv command:
It is used to move files or folders.
Syntax:
mv [source] [destination]
grep command:
It will search for the given string in the file.
Example:
grep 'line_ids' main.py
vi/nano command:
vi and nano are two text editors that can be used in the command line. If the file does not exist both text editors will create it.
Syntax:
vi [file name]
or
nano [file name]
history command: This command is used to display last used commands.
cybrosys@cybrosys:/$ history
1. sudo apt-get update
2. sudo apt-get upgrade
To copy a file from the local system to server system :
sudo scp -r [source location ] root@[server ip]: [destination location]
Example:
sudo scp -r /home/cybrosys/odoo/custom_addons root@[server ip]:/opt/odoo/
When you hit enter, it will ask the password of the local system as well as the server system. After entering both, it will start copying.
To edit file from terminal:
sudo nano [file name]
It will open the file in the nano text editor.
Example:
sudo nano /etc/odoo.conf
Save the file and restart the service.
To save the file: Ctrl+x then Y and Enter.
To start the service:
sudo systemctl start [service file]
Example:
sudo systemctl start odoo.service
To stop the service:
sudo systemctl stop [service file]
Example:
sudo systemctl stop odoo.service
To check status of the service:
sudo systemctl status [service file]
Example:
sudo systemctl status odoo.service