I am using scp task followed by sshexec in my ant build.xml. I derive the value for password from a Password field on the screen. The user doesnt have the ability to check if its the right password or not until the task completes successfully.
As a result, if the entered password is incorrect, does Scp / sshexec retry to connect? Is there any handle to limit the number of connection retries?
The sshexec and scp tasks use Java Secure Channel JSch, see ant manual library dependencies.
I had a similiar problem, as JSch tries to authenticate 6 times configured in the com.jcraft.jsch.JSch Class. When wrong password was used, the user account got locked.
Simply patched the com.jcraft.jsch.JSch Class like this :
from :
config.put("MaxAuthTries", "6");
to :
config.put("MaxAuthTries", "3");
Means JSch will only try 3 times to authenticate.
-- Edit after comment --
Download JSch release zip here - the latest version is 0.1.51
Unzip
Open jsch-0.1.51/src/main/java/com/jcraft/jsch/JSch.java
Change line 124
from
config.put("MaxAuthTries", "6");
to
config.put("MaxAuthTries", "3");
Save
Run jsch-0.1.51/build.bat or build.sh according to your OS
Use jsch-0.1.51/dist/lib/jsch-0.1.5.jar
Here a solution which does not require you to manually patch and rebuild the JSch library.
In order to limit the retry count to 1, just add the following script snippet either at the beginning of your Ant script, or before invoking scp and sshexec tasks, e.g.:
<script language="javascript"> <![CDATA[
com.jcraft.jsch.JSch.setConfig("MaxAuthTries", "1");
]]> </script>
<sshexec host="..." username="..." password="..." command="..."/>
You'll need JSch 0.1.46 or higher! I tested with Ant 1.9.4 and JSch 0.1.51 / 0.1.52.
Related
I am trying to setup openbravo on eclipse environment with the above URL.
Development stack setup is done successfully. (ANT, Java, Postgresql)
At the openbravo source directory when i apply the command
ant install.source
Build failure due to errors -
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/build.xml:480: The following error occurred while executing this line:
480 <ant dir="${base.src}" target="compile.complete.development" inheritAll="true" inheritRefs="true" />
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/src/build.xml:874: The following error occurred while executing this line:
874 <jvmarg line="${env.CATALINA_OPTS}" />
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/src/build.xml:880: Directory
880 <jvmarg value="-Djava.io.tmpdir=${env.CATALINA_BASE}/temp" />
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not successful for an unknown reason
Any help would be appreciated. Thanks.
Sounds like a permission problem.
See the related section 'Permission issues' in openbravo wiki
EDIT
for the remaining issues, i believe the properties base.src, CATALINA_OPTS and CATALINA_BASE are not set properly. Check this via :
<echo>
$${base.src} => ${base.src}
$${env.CATALINA_OPTS} => ${env.CATALINA_OPTS}
$${env.CATALINA_BASE} => ${env.CATALINA_BASE}
</echo>
or simply output all available properties use :
<echoproperties/>
also consider, before using ${env.whatever} you need to use :
<property environment="env"/>
before !
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not successful for an unknown reason
Give the permission to webapps folder
sudo chmod -R 777 /var/lib/tomcat6/webapps/
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not
successful for an unknown reason
it seem permission problem. It is important to always us the correct user account to start / stop tomcat!
Conceptually there are two user accounts involved in working with Openbravo:
command-line user used to work with files & compile Openbravo
user account used by Apache Tomcat service
There are several overlapping areas in which one of the accounts needs to access and modify files from the other account in both directions.
To avoid any problems Openbravo strongly recommends to run Apache Tomcat services with the same user account which is used on command line. As that way the above topic will be perfectly solved easily.
source: http://wiki.openbravo.com/wiki/Installation/Custom/Apache_Tomcat
I would like to ask you for some help. How can I use an scp task when my username contains an # sign?
I tried to escape the character in many ways but it isn't working. In the following example, my username is user#host.com
<scp file="test.txt" todir=""user#host.com":password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="'user#host.com':password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="user\#host.com:password#ftp.host.com:/" trust="true" sftp="true"/>
But the output is always the same:
neither password nor keyfile for user "user has been given. Can't authenticate.
Please, is there anyway to force the task to parse this string correctly? Thank you very much.
By the way, I don't know why but with my current provider it is impossible to create a username without appending the hostname.
I use the SCP task in my build.xml and it's form looks like this:
<scp file="package/ROOT.war" todir="user#example.com:~" trust="true" password="${password}"/>
Looking at the source of the SCP Task at the function parseUri(String uri) (line 370) it appears that the task can support a username with a # symbol. The restrictions appear to be with paths that have a : or # in them as seen by this comment:
// user:password#host:/path notation
// everything upto the last # before the last : is considered
// password. (so if the path contains an # and a : it will not work)
The code doesn't seem to support this comment (as pointed out by
martin clayton). You can also see the error you are referring which is triggered when the password or the keyfile is missing. Maybe the combination of a password in user:password#host:/path notation and a username with an # is causing problems?
Present ant version -1.9.4 operating system:-16.04 Ubuntu did not work.
Changed to 1.9.3 and pointed to /usr/bin/ant ssh was successful
observation:
16.04 and ant 1.9.3 is working
14.04 ant 1.9.4 is working
I would like to ask you for some help. How can I use an scp task when my username contains an # sign?
I tried to escape the character in many ways but it isn't working. In the following example, my username is user#host.com
<scp file="test.txt" todir=""user#host.com":password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="'user#host.com':password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="user\#host.com:password#ftp.host.com:/" trust="true" sftp="true"/>
But the output is always the same:
neither password nor keyfile for user "user has been given. Can't authenticate.
Please, is there anyway to force the task to parse this string correctly? Thank you very much.
By the way, I don't know why but with my current provider it is impossible to create a username without appending the hostname.
I use the SCP task in my build.xml and it's form looks like this:
<scp file="package/ROOT.war" todir="user#example.com:~" trust="true" password="${password}"/>
Looking at the source of the SCP Task at the function parseUri(String uri) (line 370) it appears that the task can support a username with a # symbol. The restrictions appear to be with paths that have a : or # in them as seen by this comment:
// user:password#host:/path notation
// everything upto the last # before the last : is considered
// password. (so if the path contains an # and a : it will not work)
The code doesn't seem to support this comment (as pointed out by
martin clayton). You can also see the error you are referring which is triggered when the password or the keyfile is missing. Maybe the combination of a password in user:password#host:/path notation and a username with an # is causing problems?
Present ant version -1.9.4 operating system:-16.04 Ubuntu did not work.
Changed to 1.9.3 and pointed to /usr/bin/ant ssh was successful
observation:
16.04 and ant 1.9.3 is working
14.04 ant 1.9.4 is working
I am seeing this error for quite sometime now.
I am running ant build on CYGWIN which inturn runs on WindowsXP.
The resolution(bad one) I found was to delete my gcct/first directory and run ant build again (which runs from another directory). It runs successfully but if I modify some code under gcct/first, I do not want to delete it because of this error.
I did see this link. The resolution here does not apply to me since I do not have .cvspass defined anywhere in the build.xml.
C:\svn\CEL_v3681\buildCore.xml:1883: cvs exited with error code 1
Command line was [Executing 'cvs' with arguments:
'checkout'
'-A'
'-rfirst_v2_126'
'gcct/first'
The ' characters around the executable and arguments are
not part of the command.
environment:
ALLUSERSPROFILE=C:\Documents and Settings\All Users
ANT_HOME=C:/Apps/Apache/apache-ant-1.7.0
APPDATA=C:\Documents and Settings\shankarc\Application Data
CLASSPATH=./;C:/Program Files/Java/jre1.5.0_07/lib/ext/QTJava.zip
COMMONPROGRAMFILES=C:\Program Files\Common Files
COMPUTERNAME=NYKPWM2035798
COMSPEC=C:\WINNT\system32\cmd.exe
CUSTPROF=Roaming700Live
CVSROOT=:pserver:shankarc#amcvs2.lehman.com:/home/eqcvs/cmte
CVS_RSH=/bin/ssh
FP_NO_HOST_CHECK=NO
HOME=C:\Apps\CYGWIN\home\shankarc
HOMEDRIVE=F:
HOMEPATH=\
HOSTNAME=nykpwm2035798
IDEA_PROPERTIES=C:\Documents and Settings\shankarc\idea.properties
INFOPATH=/usr/local/info:/usr/share/info:/usr/info:
JAVA_HOME=C:/Program Files/Java/jdk1.6.0_21/
JDK_HOME=C:\Program Files\Java\jdk1.6.0_21\
LOGONSERVER=\\NYKPSM00069
MANPATH=/usr/local/man:/usr/share/man:/usr/man::/usr/ssl/man
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
PATH=C:\Apps\CYGWIN\usr\local\bin;C:\Apps\CYGWIN\bin;C:\Apps\CYGWIN\bin;C:\Apps\CYGWIN\usr\X11R6\bin;C:\Apps\Apache\apache-ant-1.7.0\bin;C:\Program Files\Java\jdk1.6.0_21\bin\;C:\Apps\CYGWIN\bin;C:\Program Files\VisualSVN Server\bin;C:\Program Files\Sudowin\Clients\Console;C:\Program Files\Fortify Software\Fortify 360 v2.5.0\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
PRINTER=\\NYKPSM04020\NYKLPR1301-03-03C05
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 6, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0f06
PROFGROUP=FONP
PROGRAMFILES=C:\Program Files
PROMPT=$P$G
PWD=/cygdrive/c/svn/CEL_v3681/gcct/cel
QHOME=c:\q
QTJAVA=C:\Program Files\Java\jre1.5.0_07\lib\ext\QTJava.zip
SESSIONNAME=Console
SHLVL=1
SITECODE=NYK
SITEIDENT=NYK
SVN_ASP_DOT_NET_HACK=1
SYSTEMDRIVE=C:
SYSTEMROOT=C:\WINNT
TEMP=C:\TEMP
TERM=cygwin
TMP=C:\TEMP
UATDATA=C:\WINNT\system32\CCM\UATData\D9F8C395-CAB8-491d-B8AC-179A1FE1BE77
USER=shankarc
USERDNSDOMAIN=INTRANET.BARCAPINT.COM
USERDOMAIN=INTRANET
USERNAME=shankarc
USERPROFILE=C:\Documents and Settings\shankarc
WINDIR=C:\WINNT
CVS_PASSFILE=C:\Apps\CYGWIN\home\shankarc\.cvspass]
Total time: 58 seconds
How I resolve this?
I had the same issue and found that even though I was not using .cvspass I did have a build property of cvs.pass set which needed to be reset to OVERRIDE to function depending on how you set up your cvs access (though it looked similar from your post). This needed to be changed in build.properties and .build.properties. Hope this helps!
I have one requirement: copy local files to remote system.
I have done the following:
downloaded jsch-0.1.44.jar and copied to lib folder of Ant
set the path and every thing
My buildfile is:
<project name="ImportedBuild" default="all">
<target name="copyFileToRemote">
<echo>2222222222 copyFileToRemote Examples:::::::::::::</echo>
<scp file="sample.txt" todir="${username}:${password}#${hostname}:/shared"/>
</target>
</project>
When I run Ant, I get this error:
BUILD FAILED com.jcraft.jsch.JSchException: reject HostKey: 10.184.74.168
at com.jcraft.jsch.Session.checkHost(Session.java:712)
at com.jcraft.jsch.Session.connect(Session.java:313)
at com.jcraft.jsch.Session.connect(Session.java:154)
at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:212)
at org.apache.tools.ant.taskdefs.optional.ssh.Scp.upload(Scp.java:291)
at org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:203)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
... etc ...
Any ideas how to resolve this?
According to the Ant scp task docs, trust attribute:
This trusts all unknown hosts if set
to yes/true. Note If you set this to
false (the default), the host you
connect to must be listed in your
knownhosts file, this also implies
that the file exists.
The trust attribute is not used in your task call, so it appears that the host (10.184.74.168) is not in your knownhosts file. Suggest you add trust="true", or add the host to the knownhosts file.
Be sure your ~/.ssh/known_hosts file is using un-hashed hostnames; if the lines start |1|base64data..., JSch appears unable to parse them. Create lines of the format hostname[,hostname|ip]* ssh-keytype base64data....
See man 8 sshd on the precise format of known_hosts, and tips on where to find the host's public key.