https://wiki.midrange.com/api.php?action=feedcontributions&user=Bmay&feedformat=atomMidrangeWiki - User contributions [en]2024-03-28T09:36:59ZUser contributionsMediaWiki 1.30.0https://wiki.midrange.com/index.php?title=SSH&diff=11388SSH2012-04-13T14:19:58Z<p>Bmay: </p>
<hr />
<div>{{AN}}, an acronym for {{bu|S}}ecure {{bu|SH}}ell, is a method to securely connect to servers where all data, even the userid and password is encrypted.<br />
SSH on iSeries can be used in several scenarios:<br />
* As a server to enable encrypted file transfer and secure remote commands<br />
* As a client to use with other secure servers<br />
* As a secure tunnel to encrypt your regular 5250 telnet sessions<br />
== Using the iSeries SSH client==<br />
These are instructions on how to use the system i ssh client for automatic, secure file transfer. <br />
Your business partner has assigned you a remote user account called yourRemoteUser. <br />
<br />
Your local system i process will run as user RUSER. <br />
=== System Requirements ===<br />
Full instructions can be found here [http://www.ibm.com/servers/enable/site/porting/tools/ http://www.ibm.com/servers/enable/site/porting/tools/].<br />
* Portable App Solutions Environment also known as [[PASE]] must be installed on the [[iSeries]] server to use ssh. Check the existence of [[licensed program]] 5722SS1 option 33. <br />
* ''See also [[#External links]]'' for the IBM Redbook.<br />
<br />
=== Setting up the user profile===<br />
Assuming that the user profile to be used is RUSER, you need to set up some folders with the correct permissions.<br />
<br />
CHGUSRPRF USRPRF(RUSER) HOMEDIR('/home/RUSER') <br />
MKDIR DIR('/home') DTAAUT(*EXCLUDE) OBJAUT(*NONE) <br />
MKDIR DIR('/home/RUSER') DTAAUT(*INDIR) OBJAUT(*INDIR) <br />
If the home directory already exists, please run <br />
CHGAUT OBJ('/home/RUSER') USER(*PUBLIC) DTAAUT(*EXCLUDE) OBJAUT(*NONE) SUBTREE(*ALL) <br />
Create the .ssh subdirectory:<br />
MKDIR DIR('/home/RUSER/.ssh') DTAAUT(*INDIR) OBJAUT(*INDIR) <br />
===Getting and storing the remote server public key===<br />
Log in as user RUSER. You can use a security officer account instead, but then you will have to reset the permissions and file ownership back to RUSER.<br />
<br />
Start the PASE shell <br />
CALL QP2TERM <br />
Execute this shell command <br />
ssh-keyscan -t rsa your.customer.com >> ~/.ssh/known_hosts <br />
Now you need to set up your own key pair.<br />
<br />
===Setting up your public and private key pair===<br />
Log in as user RUSER. You can use a security officer account instead, but then you will have to reset the permissions and file ownership back to RUSER.<br />
====Self Creation of keys====<br />
Start the PASE shell <br />
CALL QP2TERM <br />
Create the appropriate private/public keys with the ssh-keygen tool using an EMPTY passphrase, and place it in the default location in file "~/.ssh/id_rsa". <br />
ssh-keygen -b 1024 -f ~/.ssh/id_rsa -t rsa <br />
<br />
Send the public key from file "~/.ssh/id_rsa.pub" to your customer.<br />
( The public key is added by the sever admin to "~/.ssh/authorized_keys" file on the SSH server.)<br />
====Using a key issued by someone else====<br />
Your business partner may have issued you a key, and now you should use it and not create your own. <br />
In this case, copy the key file that you received into the .ssh folder. <br />
===Transferring Files===<br />
*A critical difference between most implementations of SCP/SFTP and the PASE environment version is that the commands do _not_ support the -T (tty terminal) switch. This means that authentication by password is _not_ supported. <br />
<br />
Instead, you must place your public key on the remote server you intend to connect with.<br />
<br />
====Copying files with SCP====<br />
To copy all xml files from the IN directory on the remote server to the /b2b/incoming IFS folder: <br />
scp -o IdentityFile=~/.ssh/id_rsa yourRemoteUser@your.customer.com:IN/*.xml /b2b/incoming <br />
(replace "id_rsa" with the actual name of the private key that you are to use) <br />
(The /b2b/incoming folder must exist prior to the copying.)<br />
<br />
To run batch file transfer via scp, create a script file like this (called examplescp.sh) <br />
#! /QopenSys/bin/sh <br />
scp -o IdentityFile=~/.ssh/id_rsa yourRemoteUser@your.customer.com:IN/*.xml /b2b/incoming <br />
exit <br />
Execute it in batch via command <br />
SBMJOB CMD(CALL PGM(QP2SHELL) PARM('/folderpath/examplescp.sh')) JOB(SSHJOB) USER(RUSER) <br />
<br />
====Copying files with SFTP====<br />
*Note: the SFTP is not equivalent to the OS/400 FTP client: implicit data conversion is not done (all transfers are binary), nor is there any integration with system security.<br />
<br />
We want to copy all xml files from the IN directory (inside our homedir) on the remote server to the /b2b/incoming folder and delete them from the remote server. <br />
<br />
Create a text file called ssh-input.txt that contains: <br />
get IN/*.xml /b2b/incoming <br />
rm IN/*.xml <br />
exit <br />
To run batch file transfer via sftp, create a script file like this (called examplesftp.sh) <br />
#! /QopenSys/bin/sh <br />
sftp –b ssh-input.txt -o IdentityFile=~/.ssh/id_rsa yourRemoteUser@your.customer.com <br />
exit <br />
Execute it in batch via command <br />
SBMJOB CMD(CALL PGM(QP2SHELL) PARM('/folderpath/examplesftp.sh')) JOB(SSHJOB) USER(RUSER)<br />
<br />
===Placing your own public key on the remote server===<br />
*These instructions will not work: if your public key is not on the remote server there is no way to log on to that server. It may be possible to do this using a windows or linux based client, that permits password entry.<br />
<br />
Sometimes you work with a clueless operator who does not or will not help you to place your public key on the remote server. <br />
There is a workaround that requires you to have a valid password for your account (you do have a password, don't you?).<br />
You also need write permissions you your home directory, and hopefully it does not have any public authority.<br />
<br />
Start the PASE shell <br />
CALL QP2TERM <br />
Connect to the remote server using your password. <br />
sftp yourRemoteUser@your.customer.com <br />
Check to see if there is a .ssh folder in your home directory. <br />
dir .ssh <br />
If it does not exist , create it now, and switch to it. <br />
mkdir .ssh <br />
cd .ssh <br />
If the authorized_keys file already exists, then you will have to get it to your system and append your public key to it, and then send it back. If it does not exist, then the following will suffice: <br />
put ~/.ssh/id_rsa.pub authorized_keys<br />
<br />
==Setting up an iSeries SSHD server==<br />
[http://www-03.ibm.com/servers/enable/site/porting/tools/openssh.html http://www-03.ibm.com/servers/enable/site/porting/tools/openssh.html]<br />
<br />
To run the sshd daemon on i5/OS: <br />
* The userid that starts the daemon must have *ALLOBJ special authority <br />
* The userid that starts the daemon must be 8 or fewer characters long <br />
* Before starting sshd for the first time, you will need to generate host keys: <br />
ssh-keygen -t rsa1 -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-3.5p1/etc/ssh_host_key -N "" <br />
ssh-keygen -t dsa -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-3.5p1/etc/ssh_host_dsa_key -N "" <br />
ssh-keygen -t rsa -f /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-3.5p1/etc/ssh_host_rsa_key -N "" <br />
* You can start the sshd daemon with either one of these CL commands: <br />
QSH CMD ('/QOpenSys/usr/sbin/sshd')<br />
CALL PGM(QP2SHELL) PARM('/QopenSys/usr/sbin/sshd')<br />
With IBM i 6.1 you can also use STRTCPSVR *SSHD<br />
* You can stop the sshd daemon at V5R4 by starting the PASE command shell: <br />
CALL PGM(QP2SHELL)<br />
(then issue the command to show active processes)<br />
ps ax<br />
(Find the PID number of the process for ssh and issue the kill command, if the PID is 1234...)<br />
kill 1234 <br />
<br />
<br />
The SSHD configuration file should be reviewed for fitness to your security policy. <br />
In particular, the following items should be decided upon:<br />
* The '''AllowUsers''' directive by default allows ALL active users to connect and execute PASE and system commands, even if they are limited users. Check the '''AllowUsers''', '''AllowGroups''', '''DenyUsers''' and '''DenyGroups''' directives to see what is good for you.<br />
<br />
* The '''PermitRootLogin''' directive allows QSECOFR to login via SSH<br />
<br />
== Security implications of using SSH on iSeries ==<br />
[http://archive.midrange.com/security400/200609/msg00048.html http://archive.midrange.com/security400/200609/msg00048.html]<br />
<br />
==External links==<br />
*{{Redpaper<br />
| title=Securing Communications with OpenSSH on IBM i5/OS<br />
| pubnumber=redp4163<br />
}}<br />
*[https://www-304.ibm.com/partnerworld/wps/servlet/ContentHandler/pw_com_porting_tools_openssh LPO 5733-SC1 -- IBM Portable Utilities for i]<br />
*[http://archive.midrange.com/midrange-l/200609/msg01523.html How to set up SSH client on iSeries for password-less connections] from [http://archive.midrange.com/midrange-l/index.htm midrange-l]<br />
*[http://www.youngiprofessionals.com/wiki/index.php/PASE/SSHSetup SSHSetup] at YiPs Wiki<br />
<br />
==Categories==<br />
[[Category:Definitions]]</div>Bmay