tomcat中javaweb项目sftp权限相关问题

  • 注意点
    • 用什么角色启动web项目,web项目通过sftp下载的文件就属于哪个角色
    • 配置/etc/ssh/ssh_config参数时,优先指定为组,而不是角色,
      • 因为启动web的角色如果不是sftp角色时,容易出现下载的文件不能被其他节点通过sftp获取
      • 这样就不用修改文件的相关权限,又能使文件继续流通
      • 相关参数为
        • Match User sftpuser
        • Match Group sftpuser
    • 不要把root用户拉到sftp组里,会造成节点无法通过xshell用root用户登录
    • 为安全起见,修改ssh相关配置文件,要做原配置备份,或在配置里把要改的注掉,换行补充
    • 为安全起见,ssh服务重启后要查看状态,还要在xshell的会话管理器里点击查看是否能正常连接对应的节点
    • 修改ssh配置文件,要重启sshd才能生效,如下相关日志

相关问题解决借鉴

linux下SSH远程连接服务慢解决方案 - 邱明成 - 博客园 https://www.cnblogs.com/qiumingcheng/p/5797551.html
ssh与sftp登录对端缓慢问题解决_运维_推背图的博客-CSDN博客 https://blog.csdn.net/qq_37467907/article/details/93618122

方案二:改善ssh服务
1、查看ssh 客户端配置文件/etc/ssh/ssh_config(注意不是sshd_config),修改host:GSSAPIAuthentication no,不使用GSSAPI来鉴权。
2、修改sshd_config 添加行UseDNS no关闭ssh的dns查询,然后重启sshd(这个修改对此不大)

Linux命令之sftp - 安全文件传输命令行工具-毛虫小臭臭-51CTO博客 https://blog.51cto.com/moerjinrong/2050593?utm_source=oschina-app


[root@localhost audioTemplate]# vim /etc/ssh/sshd_config 
[root@localhost audioTemplate]# service sshd restart
停止 sshd:                                                [确定]
正在启动 sshd:                                            [确定]
[root@localhost audioTemplate]# groups sftpuser
sftpuser : sftpuser lmn
[root@localhost audioTemplate]# vim /etc/ssh/sshd_config 

# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
#Subsystem      sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       ForceCommand cvs server

Subsystem sftp internal-sftp
#Match User sftpuser
Match Group sftpuser
ChrootDirectory /data/ftp_template/shendi
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
"/etc/ssh/sshd_config" 147L, 4070C       

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在java里可以通过Ganymed SSH-2, Expect4j等实现ssh登录,由于Ganymed SSH-2是纯java实现,并且可以实现scp,sftp等,因此我们采用Ganymed SSH-2 1> 下载安装 从http://code.google.com/p/ganymed-ssh-2/ 下载,我们用的是ganymed-ssh2-build251beta1.zip。 在eclipse里新建一个测试工程,并将解压后的ganymed-ssh2-build251beta1.jar拷到工程的lib目录下,然后在工程属性的java build path里添加这个jar的library。 2> ssh 将解压后的examples目录下的Basic.java 拷到工程的src目录,编译运行以后可以在控制台看到输出结果。除了执行一条命令,也可以执行一个shell脚本。 例如将Basic.java的“uname -a && date && uptime && who” 改为“/home/lss/test.sh”, test.sh的内容如下: #! /bin/sh echo "testing shell"; ls; 在eclipse里运行以后的结果为: Here is some information about the remote host: testing shell 1 test.sh ExitCode: 0 需要注意的是在一个session里只能执行一次命令,因此如果想在server上执行多个命令,要么打开多个session,要么在一个session里去执行一个shell脚本,shell脚本里去执行多个命令。 每次执行完以后,如果正确将返回ExitCode: 0,因此程序里可以通过sess.getExitStatus()来判断命令是否被正确执行。 3> scp 首先在程序里import ch.ethz.ssh2.SCPClient; 然后通过下面的方法来实现: SCPClient scpClient = conn.createSCPClient(); scpClient.put("localFiles", "remoteDirectory"); //从本地复制文件到远程目录 scpClient.get("remoteFiles","localDirectory"); //从远程获取文件 例如: scpClient.put("D:\\localTest.txt", "/home/bill/"); 需要注意的是windows的本地目录要用双斜杠来分隔目录。 scpClient.put("/home/bill/remoteTest.txt", "D:\\"); 4> sftp 首先在程序里import ch.ethz.ssh2.SFTPv3Client; SFTPv3Client sftpClient = new SFTPv3Client(conn); sftpClient.mkdir("newRemoteDir", 0755); //远程新建目录 ,第二个参数是创建的文件夹的读写权限 sftpClient.rmdir("oldRemoteDir"); //远程删除目录 另外还有创建删除文件,读写文件等接口,参见http://www.ganymed.ethz.ch/ssh2/javadoc/ch/ethz/ssh2/SFTPv3Client.html

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值