


What functions does the ssh service have - logging into remote hosts, sftp, and off-site backup of files?
Today I will introduce to you several applications of ssh. Common applications include using ssh to connect to remote servers, using sftp to transfer files, and using ssh to perform off-site backups.
Connect to the remote host
Connect to the remote server This is our most commonly used function, connect to the remote server, and then manage the server .
If your client is windows, then you need to install terminal tools, such as xshell, Terminator, Tmux, etc., and then use these terminal tools to connect to the remote server. If the client is Linux, you can use the ssh command directly.
Commonly used command usage is given below
Connect to the remote host ssh [account@]IP [-p specified port]
Without logging in, directly send a command to the remote server to execute the ssh -f [account@]IP [-p specified port] command
The following demonstrates remote connection to the server
# ssh 121.196.12.64 The authenticity of host '121.196.12.64 (121.196.12.64)' can't be established. ECDSA key fingerprint is SHA256:wx0RHE8fcCoad6YKw0Ex4NE+QjwRiTYxC2s2g/DqPUU. ECDSA key fingerprint is MD5:43:2c:7a:12:24:1d:86:3a:b0:a0:b7:95:c2:cf:7b:ab. Are you sure you want to continue connecting (yes/no)?
When you connect for the first time, you will be asked if you want to connect, enter yes here. After entering yes, you will be asked to enter a password
root@121.196.12.64's password: Welcome to Alibaba Cloud Elastic Compute Service ! Activate the web console with: systemctl enable --now cockpit.socket Last login: Thu Nov 19 16:25:42 2020 from 114.103.36.247
When you enter the password correctly, you will successfully connect to the remote server.
When the public key of the remote host is accepted, it will be saved in the file $HOME/.ssh/known_hosts. The next time you connect to this host, the system will recognize that its public key has been saved locally, skip the warning part, and directly prompt you to enter the password.
Each SSH user has its own known_hosts file. In addition, the system also has such a file, usually /etc/ssh/ssh_known_hosts, which saves some public keys of remote hosts that are trustworthy to all users.
If you want to exit the login, enter exit and wait to log in
# exit logout Connection to 121.196.12.64 closed.
Simulate ftp file transfer method: SFTP
Using SSH is used to control the remote host. If you just want to download resources from the remote server or upload local files to the server, then use sftp or scp. These two commands are also through the ssh port.
Login through sftp
# sftp root@121.196.12.64 root@121.196.12.64's password: Connected to 121.196.12.64. sftp> ? <== 输入?可查看交互命令的帮助信息
There are many commands for the interactive mode of sftp. Here are some common interactive commands, viewed from the three categories.
Commands for the remote server: such as ls, pwd, mkdir, etc.
-
Commands for the local machine: lcd, lls, etc.
Commands for uploading and downloading: put (upload files), get (download files).
The upload and download operations are demonstrated below.
# 从远程服务器下载一个文件到本地 sftp> ls 1.txt install.sh sftp> get 1.txt Fetching /root/1.txt to 1.txt /root/1.txt 100% 6 0.0KB/s 00:00 sftp> lls 1.txt install.sh job1.php job2.php job3.php learnshell logrotate_learn.log logrotate_learn.log.1.gz # 上传本地文件到服务器上 sftp> put job1.php Uploading job1.php to /root/job1.php job1.php 100% 34 0.3KB/s 00:00 sftp> ls 1.txt install.sh job1.php
Off-site file transfer: SCP
The SCP command can be used for off-site backup. The simplest usage of SCP is as follows
# 上传文件 scp [-pr] [-l 速率] file [账号@]主机:目录名 # 下载文件 scp [-pr] [-l 速率] [账号@]主机:file 目录名
Options and parameters:
-p Keep file attributes
-r Recursive operation
-l Limit the rate, followed by a value; for example, 1024 means 1024k bytes/s
For the backup of important files, follow one principle "Never put all your eggs in one basket." In addition to local backup, we should also perform off-site backup. Frequently use the scp command plus the system's scheduled tasks to perform off-site backup, such as:
* 2 1 * * scp -rp root@101.*.*.185:/backup \ > /root/backup/scp_$(date +$Y%m%d) 1>/dev/null 2>&1
For more related technical articles, please visit the linux tutorial column!
The above is the detailed content of What functions does the ssh service have - logging into remote hosts, sftp, and off-site backup of files?. For more information, please follow other related articles on the PHP Chinese website!

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

Linux network configuration can be completed through the following steps: 1. Configure the network interface, use the ip command to temporarily set or edit the configuration file persistence settings. 2. Set up a static IP, suitable for devices that require a fixed IP. 3. Manage the firewall and use the iptables or firewalld tools to control network traffic.

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
