Linux restricts user permissions, JSch, ChannelSftp, ChannelExec, java.util.InterruptedException, /etc/ssh/sshd_config, setfacl

Problem background: Other systems need to get files on the server when requesting my interface, but I don’t want to give them to users with more permissions. So I want to create a new user sftpuser on Linux. This user can only download files from the directory and subdirectories I provided, and cannot perform other […]

Complete use of jsch-springboot project

1. Add dependencies <!–linux connection shell dependency–> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.21</version> </dependency> <!– jsch way remote connection package –> <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.55</version> </dependency> 2. Tools /** * Execute Shell tool class * * @author JustryDeng * @date 2023/8/22 16:29 */ @Slf4j public class ExecuteShellUtil { /** Initialization method not called error message */ private […]

Jsch’s use demo (java’s ssh execution class)

Jsch’s use demo (java’s ssh execution class) package com.day0707; import com.jcraft.jsch.*; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Stream; /** * JSch(java ssh channel) java connection ssh service example * Remotely execute commands, upload, download * @author hehui * @date 2020/7/7 […]

Java uses jsch to download files remotely

Connect to the linux environment in the windows environment to download files remotely. The following is the implementation of selecting the jsch component. JSch (Java Secure Channel) is a java implementation of ssh2, which allows to connect to an ssh server (that is, the typical xshell connection method), and can use port forwarding, file transfer, […]

jsch–Java integrates ssh to realize remote connection

jsch–Java into ssh for remote connection Foreword At work, there are many operations to establish remote connections, such as requesting remote server data, obtaining specified files of the remote server, etc. During the development process, to access the deployed Linux platform machine, generally use xshell, etc. to configure ssh connection, user Name, password, and then […]

How does SpringBoot use WebSocket+jsch to achieve front-end and back-end interaction to obtain server logs and return to the front-end?

1. Import dependencies <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> 2. Create a new WebSocket configuration class @Component public class WebSocketConfig { @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); } } 3. Create a new WebSocket server and process the websocket logic in it @Component //register to the container @ServerEndpoint(“/webSocket”) //Receive websocket request path @Slf4j public class […]

[Solved] Error when uploading attachments using SFTP: com.jcraft.jsch.JSchException: connection is closed by foreign host

1. Questions The attachment server uses the SFTP protocol to upload attachments and reports an error: com.jcraft.jsch.JSchException: connection is closed by foreign host 2. Reason The maximum number of SSH terminal connections is 10, the maximum number of SSH terminal connections is 10, and MaxStartups is indeed 10 by default, but this number is the […]

[Solved] A custom monitoring solution based on JSch implementation service

1. Implementing custom monitoring of services based on JSch JSch is a pure Java implementation of SSH2. It allows you to connect to a sshd server, use port forwarding, X11 forwarding, file transfer and more. You can integrate its functionality into your own programs. Now that you can connect to the server through SSH, you […]