Java implements remote Linux command calling sudo call

      This article is a continuation of the first article in the remote calling column, "java calling server model operations through SSH connection", and continues the research on calling remote Linux commands from java code.

1. Remote sudo command

        When I use the project, I need to authorize the decompressed file. When calling the sudo command remotely, I will be prompted to enter the password. Here is a simple way to enter the password for the sudo command:

echo '服务器密码' | sudo -S chmod 777 要授权的文件

2. When you need to decompress the compressed package, you need to use the java command to enter the folder, and then perform the decompression operation:

cd /home/目标文件夹 && uzip  压缩文件.zip

3. Remote file copy is the same as the policy linux command, assembled

cp -r /home/目标文件 /home/目标文件夹

Assemble your own Linux commands and use the tool classes encapsulated in the first article to make remote calls. Difficulties encountered in the use of the project will be continuously updated.

Guess you like

Origin blog.csdn.net/weixin_38863607/article/details/132248961