Terrorism at the start of the second 20th century coincided with the growth of the USA as a world power. Terrorists at the time were mostly left-wing/anarchist/anti-imperialist. The start of the Vietnam War, which was viewed as a war of national liberation against France and later capitalist neo-imperial policies controlling South Vietnam equated national liberation movements with hostility to the USA.
Revolutionary movements felt that if they could show the US complicity in the military dictatorships that were propped up in the 60s and 70s in South America that they would gain popular support. This was based on the Cuban Revolution and led to the bloody uprisings, kidnappings and assassinations during the period in South America.
Israel. After the Arab defeat in 1967, the seizure of the West Bank and Gaza strip led to the foundation of the PLO. The PFLP faction imitated South American revolutionaries, first against Israel then against any nation that dealt with it, including the USA which was becoming Israel's chief ally and weapons supplier. Of course, this was a two edged sword as many of the Palestinian groups were Marxist and so attacked Arab dictatorships with equal fervour.
NATO membership. This was used as an excuse by leftist groups in Europe for attacks on US targets, as the USA was the cheif power in NATO. Baader-Meinhof and the Red Brigades were the two most obvious for this, though there were others. There was also overspill from the Israeli-Palestinian conflict, though most of this was not directed at explicitly US targets.
State sponsored terror. Terrorism after the Iranian Revolution came to be used as a tool of foreign policy. Iran sought to export the Revolution all along the Shia crescent, which the USA opposed, not at least because of Reagan's election and "proactive" stance on terrorism (as the hostage crisis propelled him to office). When the USA intervened in the Lebanon, part of the Shia Crescent, Iran's proxies in the Hezbollah attacked the military forces there to stop them backing Israel and the conservative Christian factions in the country.
They also attacked embassies in neutrals, such as Kuwait, as an extension of the policy to push America from the crescent. Kidnappings were also instigated by Iran to gain the release of its personnel from US custody, as well as stop interference in Iraq (the reasoning behind Buckley's death) and to release Shiite prisoners from Israeli jails. All calculated to further Iranian interests, with a religious overtone. As the Hezbollah had success with its methods, it inspired others, such as Palestinian groups to also kidnap Americans to obtain the release of their people in jail.
Religious terrorism, the Gulf War and Afghanistan. Postwar sanctions against Iraq perpetuated that conflict, mobilising anti-American sentiment. Iraq did try a limited terrorist campaign against the USA and Britain, but this mostly fell apart with the capture of Carlos the Jackal by the French. Saddam did not trust Islamic terrorists and so sought out ideological leftists like Carlos and his contacts for attacks. Iran continued to use terrorism as a tool of foreign policy openly, until the Khobar tower attacks implicated them. Along with a newer, less radical leadership, their guilt in the matter caused them to lessen greately their use of this strategy in the future, though they still maintain links to such groups.
The neglect of Afghanistan after the fighting allowed for the most vicious groups, notably the Taliban, to take control of the country. Many Arab fighters returned home, radicalised, extremly experienced in fighting and with a grudge against their despotic, apostate leaders at home. They came to similar conclusions as the South Americans in the 60s, that the USA was supporting corrupt regimes in the Middle East (such as Egypt, Saudi Arabia etc) that were not of the True Faith.
Links between groups also proliferated. Because of the immense wealth of Bin Laden, many groups signed alliances and merged with his, such as Islamic Jihad in Egypt. Needless to say, the increased manpower was indoctrinated in Bin Laden's ideology, which included his fatwa against American interests and America. His strategy was based on attacking the USA to cause the dictatorships in the Middle East crumble and bring about Islamic states.
Conclusion: US global interventionism and poor choice of allies has been the main reason for terrorist attacks on the USA and its interests. The precedents of the Lebanon and Somalia lead terrorists of the present to believe they can force a US withdrawl from the Middle East. Attacks do not happen unless there is a belief they will have an effect on policy, the raison d'etre of terrorism.