Linux SysOps SSH Tutorial: Learn how to perform remote server management step by step, specific code examples are required
Introduction:
SSH (Secure Shell) is a A protocol for remote login and secure data transmission over the network. For Linux system administrators (SysOps), it is crucial to be proficient in the use of SSH. This article will introduce the basic concepts of SSH, as well as the steps on how to use SSH for remote server management, and provide specific code examples.
Use the following command to install the SSH server:
sudo apt-get install openssh-server
After the installation is complete, edit /etc /ssh/sshd_config
File configuration:
Port 22 #设置SSH服务监听的端口号 PermitRootLogin no #禁止以root用户登录 PasswordAuthentication yes #启用密码身份验证
After saving and exiting the editor, restart the SSH service:
sudo service ssh restart
Use the following command on the local terminal to connect to the remote server:
ssh username@remote_server_ip
yes
Confirm acceptance. Generate public key-private key pair:
ssh-keygen -t rsa
Upload the public key to the remote server:
ssh-copy-id username@remote_server_ip
Next, you can use the private key for password-free authentication:
ssh -i /path/to/private_key username@remote_server_ip
Transfer files from local to remote server (example is to transfer local file local_file.txt
to remote server):
scp /path/to/local_file.txt username@remote_server_ip:/path/to/remote_file.txt
Download files from the remote server (the example is to download the remote server file /path/to/remote_file.txt
to the local):
scp username@remote_server_ip:/path/to/remote_file.txt /path/to/local_file.txt
Execute the command on the remote server and get the output:
ssh username@remote_server_ip 'command'
Example: View the CPU usage on the remote server:
ssh username@remote_server_ip 'top -n 1 | grep Cpu'
Conclusion:
Through this article, we learned how to install and configure the SSH server, and how to use SSH for remote server management. SSH provides a convenient remote management tool, which can greatly improve the work efficiency of Linux system administrators. By mastering these basic knowledge and code examples, I hope readers can better understand and apply SSH technology and improve their abilities in the system management field.
The above is the detailed content of Linux SysOps SSH Tutorial: Learn step-by-step how to manage remote servers. For more information, please follow other related articles on the PHP Chinese website!