Disable telnet and enable ssh on Cisco Switch (IOS)

We recently purchased a Cisco switch for our Hadoop cluster. So I wanted to set up the Cisco switch. But first of all, I want to configure ssh and disable telnet. Let's see how we can do that.
Connect to the switch using telnet or using the console port. (You should enable telnet and give a password from express setup.)
configure terminal
hostname <switchname>
ip domain-name <domain name>
crypto key generate rsa
Enter "1024" when it prompts for
How many bits int the modulus [512]:
Then run below commands
interface fa0/0
ip address
no shutdown
username <username> priv 15 secret <password>
aaa new-model
enable secret <password>
If you have a Cisco router use "0 4" instead of "0 14"
line vty 0 14
transport input ssh
copy running-config startup-config
Now you can use SSH client to connect to switch.