在CentOS上使用SSH进行文件传输,通常有两种方法:SCP(Secure Copy Protocol)和SFTP(SSH File Transfer Protocol)。以下是这两种方法的详细步骤:
安装SCP: SCP通常是预装的,但如果没有,可以使用以下命令安装:
sudo yum install openssh-clients
从本地传输到远程:
scp /path/to/local/file username@remote_host:/path/to/remote/directory
例如:
scp /home/user/document.txt user@192.168.1.100:/home/user/remote_directory
从远程传输到本地:
scp username@remote_host:/path/to/remote/file /path/to/local/directory
例如:
scp user@192.168.1.100:/home/user/remote_document.txt /home/user/local_directory
启动SFTP会话:
sftp username@remote_host
例如:
sftp user@192.168.1.100
在SFTP会话中进行文件传输:
上传文件到远程服务器:
put /path/to/local/file /path/to/remote/directory
例如:
put /home/user/document.txt /home/user/remote_directory
从远程服务器下载文件:
get /path/to/remote/file /path/to/local/directory
例如:
get /home/user/remote_document.txt /home/user/local_directory
退出SFTP会话:
exit
~/.ssh/authorized_keys
文件中。通过以上步骤,你可以在CentOS上使用SSH进行安全的文件传输。