Generate Ssh Key Rhel 6

  1. Generate Ssh Key Rhel 6 1
  2. Create Ssh Key Rhel 7
Learning has never been so easy!

A colleague and I were recently discussing how he preps his RHEL template VMs for use with Puppet. It inspired me to share how I prepare my Linux VMs to become a template within vSphere 6.5. A point to note is that I don’t prepare my template images for a particular configuration management system like Puppet, but instead bootstrap them once they’re deployed. Why? I use my templates for a variety of things, and sometimes the people who end up with the VMs don’t want my management systems on them. It also means I have to handle manually some of what is done scriptwise via the configuration management system, but that’s just fine. I’d actually rather do it that way because it helps me guarantee the state of the system.

Note: This is an RHCSA 7 exam objective and an RHCE 7 exam objective. Instead of connecting through login/password to a remote host, SSH allows you to use key-based authentication. To set up key-based authentication, you need two virtual/physical servers that we will call server1 and server2. Configuration Procedure. Dec 01, 2018  Where, You generate a key pair on your Linux/Unix/macOS desktop. Place the public key on RHEL 8 server. One can unlock public key using a private key stored on your desktop with the help of ssh command.

When a user logs into a remote Red Hat Enterprise Linux 6 system using SSH, they receive a command prompt allowing them to enter commands on the remote system as if they were sitting at the remote system and had opened a terminal session. In this chapter we will cover the steps necessary to configure an RHEL 6 system to accept SSH connections.

You can perform these steps in full multiuser — runlevel 3 — or in single-user by issuing an “init 1” and waiting for all the processes to stop. I wouldn’t do any of this in runlevel 5, with full X Windows running. In fact, I really don’t suggest installing X Windows at all on Linux VMs unless you really, really need it for some reason… but that’s a whole different topic. I’d also suggest taking a snapshot of your template prior to trying any of this out. As Lenin said, “Trust, but verify.”

I'm just setting up a fresh install of Centos 6 (my first time with 6) and have inserted the public key into the authorizedkeys file - I'm using the same public/private key pair that I already use for several other servers (including several other centos 5 systems) Using username 'root'. Server refused our key root@192.168.0.174's password. I need to automate ssh-keygen -t rsa with out a password i.e. Enter at the prompt. How can I do that from a shell script? Automate ssh-keygen -t rsa so it does not ask for a passphrase. Ask Question Asked 7 years. How to generate public key from windows command prompt. Enabling rsync with ssh keygen and no password. May 22, 2007 Howto Linux / UNIX setup SSH with DSA public key authentication (password less login) last updated May 22, 2007 in Categories BASH Shell, CentOS, Debian / Ubuntu, FreeBSD, HP-UX Unix, Linux, Networking, OpenBSD, RedHat and Friends, Security, Suse, Ubuntu Linux, UNIX. This tutorial explains how to configure and manage SSH Server and SSH Client in Linux step by step with practical examples. Learn how to install, enable and start SSH Server and SSH client; generate SSH public keys and SSH private keys for key based authentication and configure User and Host Based Security in detail.

This write up assumes you have a fresh RHEL/CentOS install running that has been updated and has your required packages installed. You must also ensure that open-vm-tools is installed before proceeding.

Points to note on the install:

- Don't create a local user (use a root account only)
- Make sure the disk is thin provisioned
- Ensure that the network is enabled and leave it set as DHCP for now

I like to use the --skip-broken flag when running yum update. It's a great feature for skipping packages that have dependency problems or that may introduce problems to the already installed packages.

i.e: yum update --skip-broken -y

12 Steps total

Step 1: Stop the Logging Services

You’re going to all this trouble to create a clean deployable template, so you might as well stop writing new data. Otherwise all your deployed VMs will have a log of you shutting the VM down.

Issue the following commands to stop the logging services:

/sbin/service rsyslog stop
/sbin/service auditd stop

Step 2: Remove any old kernels

You need yum-utils installed to get package-cleanup. This has to go before the yum cleanup in the next step as it needs your channel data. I usually let the post-deployment configuration management take care of this, but this is nice when we create a new template for a intermediate/point release, or just to cover a security hole.

Issue the following command to remove the old kernels (if there are any):

package-cleanup --oldkernels --count=1

Step 3: Clean out Yum

Yum keeps a cache in /var/cache/yum that can grow quite large, especially after applying patches to the template. For example, my lab host currently has 360 MB of stuff in yum’s cache right now, just from a few months of incremental patching. In the interest of keeping my template as small as possible I wipe this.

Issue the following command to clean the cache:

yum clean all

Step 4: Force the logs to rotate and remove old logs we don’t need

Starting fresh with the logs is nice. It means that you don’t have old, irrelevant log data on all your cloned VMs. It also means that your template image is smaller. Change out the “rm” command for one that matches whatever your logrotate renames files as. As an aside, because people usually neglect this step, if you get really, really bored it’s fun to look at the old log data people leave on virtual appliances in cloud templates. Lots of leaked information there ;)

Generate Ssh Key Rhel 6 1

Issue the following commands to clear the logs:

/usr/sbin/logrotate –f /etc/logrotate.conf
/bin/rm –f /var/log/*-???????? /var/log/*.gz
/bin/rm -f /var/log/dmesg.old
/bin/rm -rf /var/log/anaconda

Step 5: Truncate the audit logs (and other logs we want to keep placeholders for)

This whole /dev/null business is a neat function that lets you clear a file without restarting the process associated with it, useful in many more situations than just template-building.

Issue the following commands to truncate the audit logs:

/bin/cat /dev/null > /var/log/audit/audit.log
/bin/cat /dev/null > /var/log/wtmp
/bin/cat /dev/null > /var/log/lastlog
/bin/cat /dev/null > /var/log/grubby

Step 6: Remove the udev persistent device rules

Have you ever noticed that if you clone/deploy a Linux VM that won't bring up it single network interface and renames the interface to something like eth1? Yep, well that's the udev persistent network interface rules coming back to haunt you. This is how I've decided to deal with the problem.

This generally affects CentOS /RHEL 6 and you shouldn't have to do it in v7 but it won't hurt anything.

Issue the following command to remove the udev persistent rules:

/bin/rm -f /etc/udev/rules.d/70*

Step 7: Remove the traces of the template MAC address and UUIDs

This is a corollary to step 5, just removing unique identifiers from the template so the cloned VM gets its own. You can also change the “-i” to “-i.bak” if you want to keep a backup copy of the file.

Here we update some Xbox live code/gift card from the above generator if the status shows “Already Used” then the code will not work if the status shows “Activate Now” then you can use it by activating code. But you can use above located generator to generate unlimited codes for your Xbox Live, Xbox One, Xbox Gold and Xbox 360. Free Xbox live Gold & Gift Card codes! The BEST and only working Xbox code generator in 2020. Get yours now, it only takes 60 seconds and the codes are unlimited! Xbox Live code generator is an online tool that lets you generate free Xbox Live codes. Codes generated using our generator is similar to the real Xbox codes that are 25 characters long including numbers and letters. You can generate unlimited free Xbox codes using this generator. Activate xbox live code.

Issue the following command to clear the identifiers:

/bin/sed -i ‘/^(HWADDR UUID)=/d’ /etc/sysconfig/network-scripts/ifcfg-e*

Step 8: Clean /tmp out

Under normal, non-template circumstances you really don’t ever want to run rm on /tmp like this. Use tmpwatch or any other manner of safer ways to do this, since there are attacks people can use by leaving symlinks and what-not in /tmp that rm might traverse (“whoops, I don’t have an /etc/passwd anymore!”). Plus, users and processes might actually be using /tmp, and it’s impolite to delete their files. However, this is your template image, and if there are people attacking your template you should reconsider how you’re doing business really.

/bin/rm –rf /tmp/*
/bin/rm –rf /var/tmp/*

Step 9: Remove the SSH host keys

If you don’t do this all your VMs will have all the same keys, which has negative security implications. It’s also annoying to fix later when you’ve realised that you’ve deployed a couple of years worth of VMs and forgot to do this in your prep script. Not that I would know anything about that. Nope.

/bin/rm –f /etc/ssh/*key*

Step 10: Remove the root user’s shell history

No sense in keeping this history around, it’s irrelevant to the cloned VM.

Create Ssh Key Rhel 7

/bin/rm -f ~root/.bash_history
unset HISTFILE

Step 11: Remove the root user’s SSH history and other stuff

You might choose to just remove ~root/.ssh/known_hosts if you have SSH keys you want to keep around.

/bin/rm -rf ~root/.ssh/
/bin/rm -f ~root/anaconda-ks.cfg

Step 12: Clear bash history and shutdown for template creation

Generate ssh key rhel 6 0

Time to clear the history of everything you've just done and shutdown the server in a clean state for converting to a VM:

history –c
sys-unconfig

The server will automatically now shutdown.

So that’s my prep routine. It relies heavily on keeping the rest of the VM clean, and only cleans up what we can’t avoid sullying. Once the server shuts down as a result of the sys-unconfig command you can convert to a sanitized template in vSphere and add any customization specs required to the Linux deployments.

3 Comments

  • Poblano
    MasterChewie74 Aug 28, 2018 at 10:31pm

    Hey Liam,
    Awesome How To article! It really helped me out with a project I'm working on! If it's alright, I do have one question about doing the deployments from a template. I'm currently working with SUSE Enterprise Linux 12 and I noticed that when I deploy off a template, the /sda1 and /sda2 UUIDs are the same in every clone. Is this something that I need to change? Or can several servers with the same device UUIDs exist? If I need to change them, how should I go about it?
    Thank you in advance for any and all help you may be able to provide!!!

  • Pimiento
    spicehead-gvo1u Sep 17, 2018 at 03:48am

    MC, I blieve you will want to place this in your cleanup script:

    echo '> Remove the traces of the template MAC address and UUIDs'
    sudo sed -i '/^(HWADDR UUID)=/d' /etc/sysconfig/network-scripts/ifcfg-e*

    Hope this helps..

  • Sonora
    sibzz Jan 10, 2019 at 06:24am

    Great guide. Step 6 was specially interesting for me . That udev trick is very neat. Will be using it from now on.