SlideShare a Scribd company logo
CentOS 5 SSH+SFTP for remote
access and secure file transfers
[OpenSSH]
Submitted by firewing1 on Wed, 05/04/2011 - 18:42
This how-to will show you how to configure:
Remote access over SSH via OpenSSH
o Secure, password-less authentication
o Optional: OpenSSH 5.4p1 to allow restrict shell access and jail users by group
Secure file transfers over SFTP

Configuring OpenSSH
openssh-server is already installed by default, it just needs to be configured. We will
disable root logins as well as all password-based logins in favour of the more secure public
key authentication. If you do not already have a SSH key, you should take the time to
create one now by running ssh-keygen on the computer you will be using to access the
server remotely.
The following will configure SSH as described above:
cat << EOF >> /etc/ssh/sshd_config
#
## Customizations ##
# Some of the settings here duplicate defaults, however this is to ensure that
# if for some reason the defaults change in the future, your server's
# configuration will not be affected.
# Do not allow root to login over SSH. If you need to become root, login as your
# regular use and use su - instead.
PermitRootLogin no
# Disable password authentication and enable key authentication. This will
# force users to use key-based authentication which is more secure and will
# protect against some automated brute force attacks on the server. As well,
# this section disables some unneeded authentication types. If you wish to use
# them, modify this section accordingly.
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
KerberosAuthentication no
# Do not allow TCP or X11 forwarding by default.
AllowTcpForwarding no
X11Forwarding no
# Why give such a large window? If the user has not provided credentials in 30
# seconds, disconnect the user.
LoginGraceTime 30s
EOF

Let's make sure SSH starts on boot, restart the service immediately and finally add the
firewall exception for port 22:
chkconfig sshd on
service sshd restart
iptables -I RH-Firewall-1-INPUT 4 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
service iptables save

Because we have disabled root access over SSH, it is time to create a regular user that you
can used to login over ssh and then gain root access:
useradd myusername
passwd myusername
su - myusername
mkdir -m 0700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
exit
restorecon -v -r /home/myusername

Now add the contents of your ~/.ssh/id_rsa.pub file to .ssh/authorized_keys on the server.

Optional (but recommended): Rebuilding OpenSSH 5.x
Although SSH will function perfectly fine with this bare configuration, it is not the most
secure possible. CentOS 5 comes with OpenSSH version 4.3p2 which is rather outdated.
Instead of using 4.3p2, OpenSSH version 5.4p1 (from Fedora 13) can be rebuilt which
offers a slew of new features such as access control via user/group matching and SFTP
jailrooting.
yum install fedora-packager
su - myusername
cd ~/rebuilds
fedpkg clone -a openssh
cd openssh
fedpkg switch-branch f13

Before the package can be rebuilt, a few changes need to be made to make it work on
CentOS 5. Edit openssh/F-13/openssl.spec and find the line BuildRequires: tcp_wrappersdevel at approximately line number 142. Simply remove the -devel so that the line now
readsBuildRequires: tcp_wrappers. Just below, you will also notice a
statement BuildRequires: openssl-devel >= 0.9.8j.
Remove the version requirement so that the line reads BuildRequires: openssl-devel. Lastly,
near line 178 find the lineRequires: pam >= 1.0.1-3 and once again, remove the version
requirement so that the line reads Requires: pam.
Now that the RPM spec file has been modified, we also need to change the PAM
configuration file as the one from Fedora 13 uses some modules that are not present in
CentOS 5:
cat << EOF > sshd.pam
#%PAM-1.0
auth
include
system-auth
account
required
pam_nologin.so
account
include
system-auth
password
include
system-auth
# pam_selinux.so close should be the first session rule
session
required
pam_selinux.so close
session
required
pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user
context
session
required
pam_selinux.so open env_params
session
optional
pam_keyinit.so force revoke
session
include
system-auth
EOF

The package is ready to be rebuild for CentOS 5. Execute the following to rebuild and
install OpenSSH 5.4p1:
yum install gtk2-devel libX11-devel autoconf automake zlib-devel audit-libs-devel pamdevel fipscheck-devel openssl-devel krb5-devel libedit-devel ncurses-devel libselinuxdevel xauth
fedpkg local
exit
rpm -Uhv /home/myusername/rebuilds/openssh/[arch]/openssh-{5,server,clients}*.rpm
rm -f /etc/ssh/sshd_config.rpmnew

Remember to replace [arch] in the second to last command with the appropriate value (most
probably i686 for 32-bit machines or x86_64 for 64-bit machines). We can take now
advantage of the new features to harden SSH! The configuration segment below will
restrict access for members of the serv_sftponly group such that only SFTP access is
permitted and those users are jailed to the "web" folder in their home directory (so that they
can only upload/download files from their website). Members of the serv_sshall group have
full SSH and SFTP access, as well as X11 and TCP forwarding.
mkdir /srv/sftp
groupadd serv_sftponly
groupadd serv_sshall
usermod -a -G serv_sshall myusername
sed -i'' 's|Subsystemtsftpt/usr/libexec/openssh/sftpserver|#Subsystemtsftpt/usr/libexec/openssh/sftp-server|' /etc/ssh/sshd_config
cat << EOF >> /etc/ssh/sshd_config
#
## Access control ##
# We need to use the internal sftp subsystem
Subsystem
sftp
internal-sftp
# Allow access if user is in these groups
AllowGroups serv_sftponly serv_sshall
# We can't use a path relative to ~ (or %h) because we make the user homes
# /public_html in order to get the chroot above working properly. As a result,
# we need to set an absolute path that will make SSH look in the usual place
# for authorized keys.
AuthorizedKeysFile /home/%u/.ssh/authorized_keys
# Give tunnelling + X11 access to users who are members of group "serv_sshall"
Match group serv_sshall
X11Forwarding yes
AllowTcpForwarding yes
# Restrict users who are members of group "serv_sftponly"
Match group serv_sftponly
# Some settings here may duplicate the global settings, just to be safe.
#PasswordAuthentication yes
X11Forwarding no
AllowTcpForwarding no
# Force the internal SFTP subsystem and jailroot the user in their home.
# %u gets substituted with the user name, %h with home
ForceCommand internal-sftp
ChrootDirectory /srv/sftp/%u
EOF
service sshd restart

The /srv/sftp/username folder is used instead of the user's entire home because it prevents
the user from making any potentially unwanted configuration changes (such as authorizing
additional ssh public keys) as well as accidentally deleting files, such as the mailfolder
which holds all of that domain's emails. One now simply needs to link /srv/sftp/username to
the appropriate web folder to jail the user there. For example:
ln -s ../../home/username/web /srv/sftp/username

You do not need to do this manually, as the user setup script will run this for you.
As well, note that the configuration includes the commented line #PasswordAuthentication
Yes in the serv_sftponly MatchGroup section. If you so wish, you can uncomment this line
to have password authentication enabled ONLY for users of the serv_sftponly group. While
password authentication is less secure than public key authentication, it is much more
convenient for your clients if you are building a shared hosting machine and if a hacker
does gain access because a user had an easy to guess password, they only gain access to a
single jailed SFTP client.

Denyhosts
You may be wondering why I haven't included any information about software that can
block repeated SSH intrusions such as denyhosts... I have placed this information, along
with other server security tips, in the security tutorial (coming soon). Please see it for more
information.

Administering the server
Setting up the scripts
The following code will setup the "hosting_user_add" script which can be used to add new
hosting users on your server:
mkdir -p /root/bin
cat << EOF > /root/bin/hosting_user_add
#!/bin/sh
# "chown root.root"s are implied, but kept to be safe
if [ -z $1 ];then
echo "Usage: $1 user1 [user2]"
exit 1
fi
for username in "$@";do
read -p "Restrict $username (make member of serv_sftponly)? [Y/n] " -t 60 -n 1
response
echo
if [ "$response" == "n" ] || [ "$response" == "N" ];then
echo "*** Creating normal user $username"
useradd -G serv_sshall $username
else
echo "*** Creating restricted user $username"
useradd -G serv_sftponly -s /sbin/nologin $username
fi
chown $username.apache /home/$username
chmod 710 /home/$username
# Set password
passwd $username
# Initialize mail storage folder
mkdir -m 0700 /home/$username/mail
chown $username.$username /home/$username/mail
# Initialize web folders
mkdir -p -m 0755 /home/$username/web
chown root.root /home/$username/web
# Web: logs
mkdir -p -m 0750 /home/$username/web/logs
chown root.$username /home/$username/web/logs
# Web: offline/private storage
mkdir -p -m 0755 /home/$username/web/storage
chown $username.$username /home/$username/web/storage
# Web: docroot
mkdir -m 0755 /home/$username/web/public_html
ln -s public_html /home/$username/web/www
# make it so they can't remove the symlink
chown -h root.root /home/$username/web/www
chown $username.$username /home/$username/web/public_html
# Web: PHP error log
touch /home/$username/web/php_error_log
chown $username.$username /home/$username/web/php_error_log
chattr +u /home/$username/web/php_error_log
# Initialize session folder
mkdir -m 0770 /var/lib/php/session/$username
chown root.$username /var/lib/php/session/$username
# SSH: SFTP login
ln -s ../../home/$username/web /srv/sftp/$username
# SSH: Authorized keys dir
mkdir -m 0700 /home/$username/.ssh
chown $username.$username /home/$username/.ssh
# Key description here
echo "your_key_here" >> /home/$username/.ssh/authorized_keys
chmod 600 /home/$username/.ssh/authorized_keys
chown $username.$username /home/$username/.ssh/authorized_keys
restorecon -v -r /home/$username
done
EOF
chmod +x /root/bin/hosting_user_add

You will need to edit /root/bin/hosting_user_add later and replace your_key_here with your
own SSH key so that you can login to the account should you ever need to test or do
administration work.

Adding a new system account
/root/bin/hosting_user_add new_username

If you are adding many accounts, you can optionally specify more than one username to
have each account be created at once. For each user specified, you will be prompted if for
both their password and restricted status. Passwords can and should be set randomly
because with key-based authentication, they should never have to enter it anyways.

More Related Content

What's hot

How to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareHow to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS Share
VCP Muthukrishna
 
How to installation and configure apache2
How to installation and configure apache2How to installation and configure apache2
How to installation and configure apache2
VCP Muthukrishna
 
Actividad configuración de cisco asa vpn
Actividad configuración de cisco asa vpnActividad configuración de cisco asa vpn
Actividad configuración de cisco asa vpnAndres Ldño
 
How To Install and Configure Splunk on RHEL 7 in AWS
How To Install and Configure Splunk on RHEL 7 in AWSHow To Install and Configure Splunk on RHEL 7 in AWS
How To Install and Configure Splunk on RHEL 7 in AWS
VCP Muthukrishna
 
SystemD Usage Guide
SystemD Usage GuideSystemD Usage Guide
SystemD Usage Guide
VCP Muthukrishna
 
How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7
VCP Muthukrishna
 
Instalar MySQL CentOS
Instalar MySQL CentOSInstalar MySQL CentOS
Instalar MySQL CentOS
Moisés Elías Araya
 
DNF Failed To Open Cache
DNF Failed To Open CacheDNF Failed To Open Cache
DNF Failed To Open Cache
VCP Muthukrishna
 
Lamp configuration u buntu 10.04
Lamp configuration   u buntu 10.04Lamp configuration   u buntu 10.04
Lamp configuration u buntu 10.04mikehie
 
MySql Restore Script
MySql Restore ScriptMySql Restore Script
MySql Restore Script
Hızlan ERPAK
 
How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7
VCP Muthukrishna
 
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
VCP Muthukrishna
 
Install odoo v8 the easiest way on ubuntu debian
Install odoo v8 the easiest way on ubuntu debianInstall odoo v8 the easiest way on ubuntu debian
Install odoo v8 the easiest way on ubuntu debian
Francisco Servera
 
Install PostgreSQL on CentOS
Install PostgreSQL on CentOSInstall PostgreSQL on CentOS
Install PostgreSQL on CentOS
Rangson Sangboonruang
 
Apache
ApacheApache
Apache
Mindtree
 
How to install odoo 15 steps on a ubuntu 20.04 lts system installation
How to install odoo 15 steps on a ubuntu 20.04 lts system installation How to install odoo 15 steps on a ubuntu 20.04 lts system installation
How to install odoo 15 steps on a ubuntu 20.04 lts system installation
Geminate Consultancy Services
 
Configuration Firewalld On CentOS 8
Configuration Firewalld On CentOS 8Configuration Firewalld On CentOS 8
Configuration Firewalld On CentOS 8
Kaan Aslandağ
 
Netmiko library
Netmiko libraryNetmiko library
Netmiko library
Manjunath annure
 
CentOS Server Gui Initial Configuration
CentOS Server Gui Initial ConfigurationCentOS Server Gui Initial Configuration
CentOS Server Gui Initial Configuration
Kaan Aslandağ
 

What's hot (20)

How to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareHow to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS Share
 
How to installation and configure apache2
How to installation and configure apache2How to installation and configure apache2
How to installation and configure apache2
 
Actividad configuración de cisco asa vpn
Actividad configuración de cisco asa vpnActividad configuración de cisco asa vpn
Actividad configuración de cisco asa vpn
 
How To Install and Configure Splunk on RHEL 7 in AWS
How To Install and Configure Splunk on RHEL 7 in AWSHow To Install and Configure Splunk on RHEL 7 in AWS
How To Install and Configure Splunk on RHEL 7 in AWS
 
SystemD Usage Guide
SystemD Usage GuideSystemD Usage Guide
SystemD Usage Guide
 
How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7
 
Instalar MySQL CentOS
Instalar MySQL CentOSInstalar MySQL CentOS
Instalar MySQL CentOS
 
DNF Failed To Open Cache
DNF Failed To Open CacheDNF Failed To Open Cache
DNF Failed To Open Cache
 
Lamp configuration u buntu 10.04
Lamp configuration   u buntu 10.04Lamp configuration   u buntu 10.04
Lamp configuration u buntu 10.04
 
MySql Restore Script
MySql Restore ScriptMySql Restore Script
MySql Restore Script
 
How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7How To Install and Configure SUDO on RHEL 7
How To Install and Configure SUDO on RHEL 7
 
Fail2ban
Fail2banFail2ban
Fail2ban
 
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
 
Install odoo v8 the easiest way on ubuntu debian
Install odoo v8 the easiest way on ubuntu debianInstall odoo v8 the easiest way on ubuntu debian
Install odoo v8 the easiest way on ubuntu debian
 
Install PostgreSQL on CentOS
Install PostgreSQL on CentOSInstall PostgreSQL on CentOS
Install PostgreSQL on CentOS
 
Apache
ApacheApache
Apache
 
How to install odoo 15 steps on a ubuntu 20.04 lts system installation
How to install odoo 15 steps on a ubuntu 20.04 lts system installation How to install odoo 15 steps on a ubuntu 20.04 lts system installation
How to install odoo 15 steps on a ubuntu 20.04 lts system installation
 
Configuration Firewalld On CentOS 8
Configuration Firewalld On CentOS 8Configuration Firewalld On CentOS 8
Configuration Firewalld On CentOS 8
 
Netmiko library
Netmiko libraryNetmiko library
Netmiko library
 
CentOS Server Gui Initial Configuration
CentOS Server Gui Initial ConfigurationCentOS Server Gui Initial Configuration
CentOS Server Gui Initial Configuration
 

Viewers also liked

Schiavone alla commissione bicamerale sui rifiuti
Schiavone alla commissione bicamerale sui rifiutiSchiavone alla commissione bicamerale sui rifiuti
Schiavone alla commissione bicamerale sui rifiutiAlessio Viscardi
 
Enseñanzas del papa francisco no. 100
Enseñanzas del papa francisco no. 100Enseñanzas del papa francisco no. 100
Enseñanzas del papa francisco no. 100monica eljuri
 
Googolplex Electric PowerCore 21
Googolplex Electric PowerCore 21Googolplex Electric PowerCore 21
Googolplex Electric PowerCore 21
Rimsky Cheng
 
Dispositvos basicos de aprendizaje
Dispositvos basicos de aprendizajeDispositvos basicos de aprendizaje
Dispositvos basicos de aprendizaje
Mar Lopez
 
Keviin
KeviinKeviin
II. La loi du Royaume
II. La loi du RoyaumeII. La loi du Royaume
II. La loi du Royaume
Pierrot Caron
 
Que es la farmacovigilancia
Que es la farmacovigilanciaQue es la farmacovigilancia
Que es la farmacovigilancia
Deyanira Piedra
 
2015 NCECA - D.E Gary Branfman
2015 NCECA - D.E Gary Branfman2015 NCECA - D.E Gary Branfman
Tenis
TenisTenis
Expertos, en hacer siempre lo mismo.
Expertos, en hacer siempre lo mismo.Expertos, en hacer siempre lo mismo.
Expertos, en hacer siempre lo mismo.
RESET® Firma Consultora en Innovación.
 
Practica Control 6
Practica Control 6Practica Control 6
Practica Control 6
Marco Salazar
 
Clinically led commissioning in the English NHS
Clinically led commissioning in the English NHSClinically led commissioning in the English NHS
Clinically led commissioning in the English NHS
Robert Varnam Coaching
 

Viewers also liked (20)

Schiavone alla commissione bicamerale sui rifiuti
Schiavone alla commissione bicamerale sui rifiutiSchiavone alla commissione bicamerale sui rifiuti
Schiavone alla commissione bicamerale sui rifiuti
 
Enseñanzas del papa francisco no. 100
Enseñanzas del papa francisco no. 100Enseñanzas del papa francisco no. 100
Enseñanzas del papa francisco no. 100
 
Cartaz(8)
 Cartaz(8) Cartaz(8)
Cartaz(8)
 
Googolplex Electric PowerCore 21
Googolplex Electric PowerCore 21Googolplex Electric PowerCore 21
Googolplex Electric PowerCore 21
 
Dispositvos basicos de aprendizaje
Dispositvos basicos de aprendizajeDispositvos basicos de aprendizaje
Dispositvos basicos de aprendizaje
 
Touch fade 3
Touch fade 3Touch fade 3
Touch fade 3
 
Keviin
KeviinKeviin
Keviin
 
Bad Faith Nov2013 Duty to Defende
Bad Faith Nov2013 Duty to DefendeBad Faith Nov2013 Duty to Defende
Bad Faith Nov2013 Duty to Defende
 
Bad Faith Nov2013 Duty of Defense Counsel
Bad Faith Nov2013 Duty of Defense CounselBad Faith Nov2013 Duty of Defense Counsel
Bad Faith Nov2013 Duty of Defense Counsel
 
Deber
DeberDeber
Deber
 
II. La loi du Royaume
II. La loi du RoyaumeII. La loi du Royaume
II. La loi du Royaume
 
Resume Updated 8-20-15
Resume Updated 8-20-15Resume Updated 8-20-15
Resume Updated 8-20-15
 
Que es la farmacovigilancia
Que es la farmacovigilanciaQue es la farmacovigilancia
Que es la farmacovigilancia
 
Cartaz(10)
 Cartaz(10) Cartaz(10)
Cartaz(10)
 
Bad Faith Nov2013 Duty to Settle
Bad Faith Nov2013 Duty to SettleBad Faith Nov2013 Duty to Settle
Bad Faith Nov2013 Duty to Settle
 
2015 NCECA - D.E Gary Branfman
2015 NCECA - D.E Gary Branfman2015 NCECA - D.E Gary Branfman
2015 NCECA - D.E Gary Branfman
 
Tenis
TenisTenis
Tenis
 
Expertos, en hacer siempre lo mismo.
Expertos, en hacer siempre lo mismo.Expertos, en hacer siempre lo mismo.
Expertos, en hacer siempre lo mismo.
 
Practica Control 6
Practica Control 6Practica Control 6
Practica Control 6
 
Clinically led commissioning in the English NHS
Clinically led commissioning in the English NHSClinically led commissioning in the English NHS
Clinically led commissioning in the English NHS
 

Similar to Cent os 5 ssh

SSH for pen-testers
SSH for pen-testersSSH for pen-testers
SSH for pen-testersE D Williams
 
How to install Setup & Configure SSH Jump Server on a Linux box
How to install Setup & Configure  SSH Jump Server on a Linux boxHow to install Setup & Configure  SSH Jump Server on a Linux box
How to install Setup & Configure SSH Jump Server on a Linux box
Ezee Login
 
OpenSSH tricks
OpenSSH tricksOpenSSH tricks
OpenSSH tricks
Assem CHELLI
 
R hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing HadoopR hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing HadoopAiden Seonghak Hong
 
Server hardening
Server hardeningServer hardening
Server hardening
Teja Babu
 
Null bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web ApplicationNull bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web Application
Anant Shrivastava
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
Ajaigururaj R
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0venkatakrishnan k
 
SSH how to 2011
SSH how to 2011SSH how to 2011
SSH how to 2011
Chris Hales
 
linux_Commads
linux_Commadslinux_Commads
linux_Commads
tastedone
 
Presentation nix
Presentation nixPresentation nix
Presentation nixfangjiafu
 
Presentation nix
Presentation nixPresentation nix
Presentation nixfangjiafu
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalation
Jameel Nabbo
 
SSH.pdf
SSH.pdfSSH.pdf
SSH.pdf
AnisSalhi3
 
Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2
benjaminwootton
 
How to secure ubuntu 12.04
How to secure ubuntu 12.04 How to secure ubuntu 12.04
How to secure ubuntu 12.04 John Richard
 
Ssh cookbook
Ssh cookbookSsh cookbook
Ssh cookbook
Jean-Marie Renouard
 
Intro to SSH
Intro to SSHIntro to SSH
Intro to SSH
JP Bourget
 

Similar to Cent os 5 ssh (20)

SSH for pen-testers
SSH for pen-testersSSH for pen-testers
SSH for pen-testers
 
How to install Setup & Configure SSH Jump Server on a Linux box
How to install Setup & Configure  SSH Jump Server on a Linux boxHow to install Setup & Configure  SSH Jump Server on a Linux box
How to install Setup & Configure SSH Jump Server on a Linux box
 
OpenSSH tricks
OpenSSH tricksOpenSSH tricks
OpenSSH tricks
 
R hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing HadoopR hive tutorial supplement 1 - Installing Hadoop
R hive tutorial supplement 1 - Installing Hadoop
 
Server hardening
Server hardeningServer hardening
Server hardening
 
Null bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web ApplicationNull bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web Application
 
Linuxserver harden
Linuxserver hardenLinuxserver harden
Linuxserver harden
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0
 
SSH how to 2011
SSH how to 2011SSH how to 2011
SSH how to 2011
 
linux_Commads
linux_Commadslinux_Commads
linux_Commads
 
Presentation nix
Presentation nixPresentation nix
Presentation nix
 
Presentation nix
Presentation nixPresentation nix
Presentation nix
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalation
 
SSH.pdf
SSH.pdfSSH.pdf
SSH.pdf
 
Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2
 
How to secure ubuntu 12.04
How to secure ubuntu 12.04 How to secure ubuntu 12.04
How to secure ubuntu 12.04
 
Ssh cookbook v2
Ssh cookbook v2Ssh cookbook v2
Ssh cookbook v2
 
Ssh cookbook
Ssh cookbookSsh cookbook
Ssh cookbook
 
Intro to SSH
Intro to SSHIntro to SSH
Intro to SSH
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Cent os 5 ssh

  • 1. CentOS 5 SSH+SFTP for remote access and secure file transfers [OpenSSH] Submitted by firewing1 on Wed, 05/04/2011 - 18:42 This how-to will show you how to configure: Remote access over SSH via OpenSSH o Secure, password-less authentication o Optional: OpenSSH 5.4p1 to allow restrict shell access and jail users by group Secure file transfers over SFTP Configuring OpenSSH openssh-server is already installed by default, it just needs to be configured. We will disable root logins as well as all password-based logins in favour of the more secure public key authentication. If you do not already have a SSH key, you should take the time to create one now by running ssh-keygen on the computer you will be using to access the server remotely. The following will configure SSH as described above: cat << EOF >> /etc/ssh/sshd_config # ## Customizations ## # Some of the settings here duplicate defaults, however this is to ensure that # if for some reason the defaults change in the future, your server's # configuration will not be affected. # Do not allow root to login over SSH. If you need to become root, login as your # regular use and use su - instead. PermitRootLogin no # Disable password authentication and enable key authentication. This will # force users to use key-based authentication which is more secure and will # protect against some automated brute force attacks on the server. As well, # this section disables some unneeded authentication types. If you wish to use # them, modify this section accordingly. PasswordAuthentication no PubkeyAuthentication yes ChallengeResponseAuthentication no KerberosAuthentication no # Do not allow TCP or X11 forwarding by default. AllowTcpForwarding no X11Forwarding no
  • 2. # Why give such a large window? If the user has not provided credentials in 30 # seconds, disconnect the user. LoginGraceTime 30s EOF Let's make sure SSH starts on boot, restart the service immediately and finally add the firewall exception for port 22: chkconfig sshd on service sshd restart iptables -I RH-Firewall-1-INPUT 4 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT service iptables save Because we have disabled root access over SSH, it is time to create a regular user that you can used to login over ssh and then gain root access: useradd myusername passwd myusername su - myusername mkdir -m 0700 .ssh touch .ssh/authorized_keys chmod 600 .ssh/authorized_keys exit restorecon -v -r /home/myusername Now add the contents of your ~/.ssh/id_rsa.pub file to .ssh/authorized_keys on the server. Optional (but recommended): Rebuilding OpenSSH 5.x Although SSH will function perfectly fine with this bare configuration, it is not the most secure possible. CentOS 5 comes with OpenSSH version 4.3p2 which is rather outdated. Instead of using 4.3p2, OpenSSH version 5.4p1 (from Fedora 13) can be rebuilt which offers a slew of new features such as access control via user/group matching and SFTP jailrooting. yum install fedora-packager su - myusername cd ~/rebuilds fedpkg clone -a openssh cd openssh fedpkg switch-branch f13 Before the package can be rebuilt, a few changes need to be made to make it work on CentOS 5. Edit openssh/F-13/openssl.spec and find the line BuildRequires: tcp_wrappersdevel at approximately line number 142. Simply remove the -devel so that the line now readsBuildRequires: tcp_wrappers. Just below, you will also notice a statement BuildRequires: openssl-devel >= 0.9.8j. Remove the version requirement so that the line reads BuildRequires: openssl-devel. Lastly, near line 178 find the lineRequires: pam >= 1.0.1-3 and once again, remove the version requirement so that the line reads Requires: pam. Now that the RPM spec file has been modified, we also need to change the PAM configuration file as the one from Fedora 13 uses some modules that are not present in CentOS 5:
  • 3. cat << EOF > sshd.pam #%PAM-1.0 auth include system-auth account required pam_nologin.so account include system-auth password include system-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session optional pam_keyinit.so force revoke session include system-auth EOF The package is ready to be rebuild for CentOS 5. Execute the following to rebuild and install OpenSSH 5.4p1: yum install gtk2-devel libX11-devel autoconf automake zlib-devel audit-libs-devel pamdevel fipscheck-devel openssl-devel krb5-devel libedit-devel ncurses-devel libselinuxdevel xauth fedpkg local exit rpm -Uhv /home/myusername/rebuilds/openssh/[arch]/openssh-{5,server,clients}*.rpm rm -f /etc/ssh/sshd_config.rpmnew Remember to replace [arch] in the second to last command with the appropriate value (most probably i686 for 32-bit machines or x86_64 for 64-bit machines). We can take now advantage of the new features to harden SSH! The configuration segment below will restrict access for members of the serv_sftponly group such that only SFTP access is permitted and those users are jailed to the "web" folder in their home directory (so that they can only upload/download files from their website). Members of the serv_sshall group have full SSH and SFTP access, as well as X11 and TCP forwarding. mkdir /srv/sftp groupadd serv_sftponly groupadd serv_sshall usermod -a -G serv_sshall myusername sed -i'' 's|Subsystemtsftpt/usr/libexec/openssh/sftpserver|#Subsystemtsftpt/usr/libexec/openssh/sftp-server|' /etc/ssh/sshd_config cat << EOF >> /etc/ssh/sshd_config # ## Access control ## # We need to use the internal sftp subsystem Subsystem sftp internal-sftp # Allow access if user is in these groups AllowGroups serv_sftponly serv_sshall # We can't use a path relative to ~ (or %h) because we make the user homes # /public_html in order to get the chroot above working properly. As a result, # we need to set an absolute path that will make SSH look in the usual place # for authorized keys. AuthorizedKeysFile /home/%u/.ssh/authorized_keys # Give tunnelling + X11 access to users who are members of group "serv_sshall" Match group serv_sshall X11Forwarding yes AllowTcpForwarding yes
  • 4. # Restrict users who are members of group "serv_sftponly" Match group serv_sftponly # Some settings here may duplicate the global settings, just to be safe. #PasswordAuthentication yes X11Forwarding no AllowTcpForwarding no # Force the internal SFTP subsystem and jailroot the user in their home. # %u gets substituted with the user name, %h with home ForceCommand internal-sftp ChrootDirectory /srv/sftp/%u EOF service sshd restart The /srv/sftp/username folder is used instead of the user's entire home because it prevents the user from making any potentially unwanted configuration changes (such as authorizing additional ssh public keys) as well as accidentally deleting files, such as the mailfolder which holds all of that domain's emails. One now simply needs to link /srv/sftp/username to the appropriate web folder to jail the user there. For example: ln -s ../../home/username/web /srv/sftp/username You do not need to do this manually, as the user setup script will run this for you. As well, note that the configuration includes the commented line #PasswordAuthentication Yes in the serv_sftponly MatchGroup section. If you so wish, you can uncomment this line to have password authentication enabled ONLY for users of the serv_sftponly group. While password authentication is less secure than public key authentication, it is much more convenient for your clients if you are building a shared hosting machine and if a hacker does gain access because a user had an easy to guess password, they only gain access to a single jailed SFTP client. Denyhosts You may be wondering why I haven't included any information about software that can block repeated SSH intrusions such as denyhosts... I have placed this information, along with other server security tips, in the security tutorial (coming soon). Please see it for more information. Administering the server Setting up the scripts The following code will setup the "hosting_user_add" script which can be used to add new hosting users on your server: mkdir -p /root/bin cat << EOF > /root/bin/hosting_user_add #!/bin/sh # "chown root.root"s are implied, but kept to be safe if [ -z $1 ];then echo "Usage: $1 user1 [user2]" exit 1 fi for username in "$@";do
  • 5. read -p "Restrict $username (make member of serv_sftponly)? [Y/n] " -t 60 -n 1 response echo if [ "$response" == "n" ] || [ "$response" == "N" ];then echo "*** Creating normal user $username" useradd -G serv_sshall $username else echo "*** Creating restricted user $username" useradd -G serv_sftponly -s /sbin/nologin $username fi chown $username.apache /home/$username chmod 710 /home/$username # Set password passwd $username # Initialize mail storage folder mkdir -m 0700 /home/$username/mail chown $username.$username /home/$username/mail # Initialize web folders mkdir -p -m 0755 /home/$username/web chown root.root /home/$username/web # Web: logs mkdir -p -m 0750 /home/$username/web/logs chown root.$username /home/$username/web/logs # Web: offline/private storage mkdir -p -m 0755 /home/$username/web/storage chown $username.$username /home/$username/web/storage # Web: docroot mkdir -m 0755 /home/$username/web/public_html ln -s public_html /home/$username/web/www # make it so they can't remove the symlink chown -h root.root /home/$username/web/www chown $username.$username /home/$username/web/public_html # Web: PHP error log touch /home/$username/web/php_error_log chown $username.$username /home/$username/web/php_error_log chattr +u /home/$username/web/php_error_log # Initialize session folder mkdir -m 0770 /var/lib/php/session/$username chown root.$username /var/lib/php/session/$username # SSH: SFTP login ln -s ../../home/$username/web /srv/sftp/$username # SSH: Authorized keys dir mkdir -m 0700 /home/$username/.ssh chown $username.$username /home/$username/.ssh # Key description here echo "your_key_here" >> /home/$username/.ssh/authorized_keys chmod 600 /home/$username/.ssh/authorized_keys chown $username.$username /home/$username/.ssh/authorized_keys restorecon -v -r /home/$username done EOF chmod +x /root/bin/hosting_user_add You will need to edit /root/bin/hosting_user_add later and replace your_key_here with your
  • 6. own SSH key so that you can login to the account should you ever need to test or do administration work. Adding a new system account /root/bin/hosting_user_add new_username If you are adding many accounts, you can optionally specify more than one username to have each account be created at once. For each user specified, you will be prompted if for both their password and restricted status. Passwords can and should be set randomly because with key-based authentication, they should never have to enter it anyways.